Page 1 of 1

XPath in PHP

Posted: Wed Apr 04, 2007 8:13 pm
by joran420
I got the XPath.class.php class file and am using it and i can select single data easy but how can I select an array of matches?

Xpath->getData("/xml/*/headline")
gives me an error that there is more than one match(which there is ...but how can i make it return an array of nodes that match or something simillar?)

not sure how clear that was...its for a CMS news System

Posted: Thu Apr 05, 2007 4:56 am
by bubblenut
Where did you ge the XPath.class.php? What version of PHP are you using? If you're using PHP5 or greater you can use SimpleXML which has pretty good support for XPath and can certainly return multiple elements from a query.

Posted: Thu Apr 05, 2007 5:14 am
by mikeeeeeeey
Joran has the right idea, it's probably worth writing it yourself in SimpleXML (it's not hard, trust me) and you'll need to use a function called childNodes, which returns an array.

http://devzone.zend.com/node/view/id/688

Posted: Thu Apr 05, 2007 6:25 am
by Maugrim_The_Reaper
If you have PHP5, use SimpleXML where possible, or the libxml2 extension.

You're looking for "//nodename" to select all nodes of that name from the current node.

Posted: Thu Apr 05, 2007 1:40 pm
by joran420
thanks for the heads up guys :) I got it working but then decided to scrap XML for mySQL ....hehe :P