[RESOLVED] domxpath query select a .......

liunx

Guest
Hi.
I've got this simple xml file:

<?xml version="1.0" encoding="utf-8"?>
<items>
<item>
<time>1169838286</time>
<title>Tre</title>
<author>Tre</author>
<content>TRE his module defines a number of classes, which are explained in the following tables. Classes with an equivalent in the DOM standard are named DOMxxx.
This module defines a number of classes, which are explained in the following tables. Classes with an equivalent in the DOM standard are named DOMxxx.TRE
</content>
</item>
<item><time>1169838</time>
<title>Tre</title>
<author>Tre</author>
<content>TRE his module defines a number of classes, which are explained in the following tables. Classes with an equivalent in the DOM standard are named DOMxxx.
This module defines a number of classes, which are explained in the following tables. Classes with an equivalent in the DOM standard are named DOMxxx.TRE
</content>
</item>
<item>
<time>11698286</time>
<title>Tre</title>
<author>Tre</author>
<content>TRE his module defines a number of classes, which are explained in the following tables. Classes with an equivalent in the DOM standard are named DOMxxx.
This module defines a number of classes, which are explained in the following tables. Classes with an equivalent in the DOM standard are named DOMxxx.TRE
</content>
</item>
</items>


To get all the item nodes I've
got this code:

$xp = new domxpath($dom);
$titles = $xp->query("/items/item");
foreach ($titles as $node) {
print $node->firstChild->data . "\n";
}


Is there a way
to get only the item with
time=1169838 for instance ?

I'm looking for good tutorials
to using domxpath ;)

Thanks in advance.

Bye.Use a predicate that says that the item node's time node's text node has that value (Heh, the XPath is easier to read). /items/item[time/text()='1169838']

Oh, right, tutorials. I don't know any tutorials: I got everything I know about XPath from the source (<!-- m --><a class="postlink" href="http://www.w3.org/TR/xpath">http://www.w3.org/TR/xpath</a><!-- m -->), but I used XPath Explorer (<!-- m --><a class="postlink" href="http://www.purpletech.com/xpe/index.jsp">http://www.purpletech.com/xpe/index.jsp</a><!-- m -->) to check the above code.W3 Schools has some XPath tutorials:

<!-- m --><a class="postlink" href="http://www.w3schools.com/xpath/default.aspThanks">http://www.w3schools.com/xpath/default.aspThanks</a><!-- m --> a lot buddies :D

I used XPath Explorer to check the above code

It's very useful !


Bye.
 
Back
Top