473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

getElementById in PHP5

Hi,

I am working on PHP5 and all the xmldom related extensions are
installed and on properly.
I am trying to execute following code but some how not working.
$doc = new DomDocument();
$doc->validateOnParse = true;
$doc->load('abc.xml');
//xml file contains one element with this id
$elem = $doc->getElementById( 'eee' );

if(is_null($elem)) {
echo "<br>IT IS NULL";
}
else {
echo "<br>NOT NULL.";
}

The output shows me null every time...
Why is that?????

Thanks in advance
Manan Vyas

Oct 30 '06 #1
2 2262
On 30 Oct 2006 04:45:50 -0800, ma*******@gmail.com wrote:
>I am working on PHP5 and all the xmldom related extensions are
installed and on properly.
I am trying to execute following code but some how not working.
$doc = new DomDocument();
$doc->validateOnParse = true;
$doc->load('abc.xml');
//xml file contains one element with this id
$elem = $doc->getElementById( 'eee' );

if(is_null($elem)) {
echo "<br>IT IS NULL";
}
else {
echo "<br>NOT NULL.";
}

The output shows me null every time...
Why is that?????
The manual hints towards why:

"According to the DOM standard this requires a DTD which defines the attribute
ID to be of type ID. You need to validate your document with
DOMDocument->validate() or DOMDocument->validateOnParse before using this
function."

You've set validateOnParse, but you haven't posted the contents of abc.xml.

Does it include a DTD that defines ID?

There is a link in the user contributed notes to the following site that
explains all:

http://blog.bitflux.ch/wiki/GetElementById_Pitfalls

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Oct 30 '06 #2
Hey Friend,

Its working now...THANKS A LOT FRIEND...
Again thanks for your help and reply.

Regards,
Manan Vyas

Andy Hassall wrote:
On 30 Oct 2006 04:45:50 -0800, ma*******@gmail.com wrote:
I am working on PHP5 and all the xmldom related extensions are
installed and on properly.
I am trying to execute following code but some how not working.
$doc = new DomDocument();
$doc->validateOnParse = true;
$doc->load('abc.xml');
//xml file contains one element with this id
$elem = $doc->getElementById( 'eee' );

if(is_null($elem)) {
echo "<br>IT IS NULL";
}
else {
echo "<br>NOT NULL.";
}

The output shows me null every time...
Why is that?????

The manual hints towards why:

"According to the DOM standard this requires a DTD which defines the attribute
ID to be of type ID. You need to validate your document with
DOMDocument->validate() or DOMDocument->validateOnParse before using this
function."

You've set validateOnParse, but you haven't posted the contents of abc.xml.

Does it include a DTD that defines ID?

There is a link in the user contributed notes to the following site that
explains all:

http://blog.bitflux.ch/wiki/GetElementById_Pitfalls

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Oct 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Rob Ristroph | last post by:
I have tried out PHP 5 for the first time (with assistance from this group -- thanks!). The people I was working with have a site that uses lots of php objects. They are having problems with...
11
by: neur0maniak | last post by:
Hi, I've been eager to try out PHP5, so I've dumped it on my little dev machine. It's running WinXP with IIS5. I've put the php-cgi.exe in the "mappings" page as I'm used to doing with PHP4....
4
by: badbetty | last post by:
Dear Googlers I have installed PHP5 to run on WinXP against Apache 2. It works! ie. I have tested a few simple scripts and a basic xml document parse. I now want to try the XSL extension so I...
4
by: Skeets | last post by:
When the data structure looks like this: <page> <point id="1"> <premise> 1+1=2 </premise> </point> <point id="2"> <premise> round is better than square </premise> </point> <thought id="1">
5
by: Aziz | last post by:
Hi, I've recently contacted technical service of a web hosting company and asked them wheter or not they're gonna upgrade to PHP5 and MySQL5. Here's a quote from their response which confused me...
4
by: Chuck Anderson | last post by:
I am trying to install Php5 on my WindowsXP machine (at home, not on the 'net). I downloaded the Php Windows binary at php.net, unzipped it to c:/Php5, changed my Apache config file to use Php5...
19
by: McKirahan | last post by:
I am working in two environments neither configuration of which I can change; one's my Web host the other a client. My Web host requires the use of the ".php5" extension to use PHP v5.1.4; where...
3
by: xhe | last post by:
I have just upgraded my php version form php4 to php5. and I met this problem, and don't know if you know the solution. My site was written in PHP4, and most parts can be running smoothly in PHP5,...
8
by: FFMG | last post by:
Hi, I am slowly moving my code to php5. But I would like to make it backward compatible in case something bad happens, (and to make sure I understand what the changes are). The way the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.