Re: DOMDocument->getElementById() isn't working

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Christoph Boget wrote:
> Getting the elements by tag name, while iterating through the list I see
> that one of the nodes has an id of 'custom'.  However, when I try to get the
> element directly using getElementById(), it doesn't return the node
> properly.  Am I doing something wrong?

A common problem. See here:
http://wiki.flux-cms.org/display/BLOG/GetElementById+Pitfalls

Probably easiest to use XPath. Otherwise you have to slightly modify
your HTML...

e.g. replace your getElementById with:
    $xp = new DomXPath($oDOMDocument);
    $oCustomNode = $xp->query("//*[@id = 'custom']")->item(0);

> Also, as an aside, one thing that I found odd is that count( $aLayoutNodes )
> shows as 1 even though more are found.  Huh?

That's because $aLayoutNodes is not an array. It is a DOMNodeList
object. That means it implements the Iterator interface which means it
works with foreach, but not with e.g. count(). Use $aLayoutNodes->length
to see how many nodes there are in the list (i.e. use that as a direct
replacement for count($aLayoutNodes))

(also if the "a" prefix is meant to identify the var as an array I'd
probably change it to the "o" prefix you seem to use for objects...)

Col

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux