Page 1 of 1

documentation on DOMNodeList and nodeValue

Posted: Mon Sep 13, 2010 5:55 am
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.

Re: documentation on DOMNodeList and nodeValue

Posted: Mon Sep 13, 2010 6:13 am
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.

Re: documentation on DOMNodeList and nodeValue

Posted: Mon Sep 13, 2010 6:43 am
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.

Re: documentation on DOMNodeList and nodeValue

Posted: Mon Sep 13, 2010 8:21 am
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

Re: documentation on DOMNodeList and nodeValue

Posted: Tue Sep 14, 2010 10:12 am
by spiderplant0
Thanks pytrin, thats just what I was looking for