Home > Archive > PHP Programming > October 2006 > getElementById in PHP5
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
getElementById in PHP5
|
|
| mananvyas@gmail.com 2006-10-30, 7:04 pm |
| 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
| |
| Andy Hassall 2006-10-30, 7:05 pm |
| On 30 Oct 2006 04:45:50 -0800, mananvyas@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 :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
| |
|
| 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, mananvyas@gmail.com wrote:
>
>
> 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 :: andy@andyh.co.uk :: http://www.andyh.co.uk
> http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
|
|
|
|
|