documentation on DOMNodeList and nodeValue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
spiderplant0
Forum Newbie
Posts: 3
Joined: Mon Sep 13, 2010 5:36 am

documentation on DOMNodeList and nodeValue

Post by spiderplant0 »

Hi, I'm struggling to find decent documntation on using XPath with PHP.
I've cobbled together some code that nearly works (simplified)...

Code: Select all

$xPathDom = new DOMDocument();
@$xPathDom->loadHTML( $frameContentsStg );
$xPath = new DOMXPath( $xPathDom );
$matches = $xPath->query( "//div" );
foreach ( $matches as $match ){
    $recordContentsAy[] = $match->nodeValue;
}
'->nodeValue' is not doing quite what I want so I wanted to find out what the alternative properties and methods are that I could use in place of 'nodeValue'.
I worked out that the '->query' method returns a type 'DOMNodeList' but when I look at the php documentation (which I usually find to be very good) the only property it mentions is 'item'. http://uk.php.net/manual/en/class.domnodelist.php
Searching for 'nodeValue' in the documentation returns loads of pages but I could only find references in PHP code snippets.
Can some one please point me to a link that describes teh 'nodeValue' property and a list of the other properties and methods for use on things returned by an XPath query. Or is there a better resource that explains this fully.
Thanks.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: documentation on DOMNodeList and nodeValue

Post by requinix »

PHP's DOMDocument extension is an implementation of the W3C's DOM. Best place I know for information about that kind of thing would be w3schools.

1. What nodeValue is can vary.
2. You haven't really mentioned what you're trying to do.
3. XPath is something entirely different, but also covered somewhere at w3schools.
4. If you just want all the DIV elements, use DOMDocument's getElementsByTagName method.
spiderplant0
Forum Newbie
Posts: 3
Joined: Mon Sep 13, 2010 5:36 am

Re: documentation on DOMNodeList and nodeValue

Post by spiderplant0 »

Hi tasairis, My example is simplified. The xPath expression can be more than just a DIV.
I'm not really looking for help with one bit of PHP code, rather, I want to find a solution myself by gaining a better understanding of PHP + DOM + XPath. I've read up on xPath elsewhere. XPath isnt the problem its more on how its impemented in PHP. I'm finding it diffucult to find a comprehensive listing of all the methods and properties that are available. Hence my question on where is the desctiption of 'nodeValue'. And where is there a list of all the other properties and methods that operate on the same class that 'nodeValue' does.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: documentation on DOMNodeList and nodeValue

Post by Eran »

The documentation for the DOM classes on the PHP manual is lacking, for sure. DOMNodeList is a collection of DOMNodes so you need to read the documentation on that to understand what methods and properties are available to you.
http://www.php.net/manual/en/class.domnode.php
Despite its name, the items could also be DOMElements, so have a look there as well -
http://www.php.net/manual/en/class.domelement.php
spiderplant0
Forum Newbie
Posts: 3
Joined: Mon Sep 13, 2010 5:36 am

Re: documentation on DOMNodeList and nodeValue

Post by spiderplant0 »

Thanks pytrin, thats just what I was looking for
Post Reply