Re: XML DOM & XPath
| From: | neill | Date: | Mon, 03 Nov 2003 17:14:21 +0000 |
| Subject: | Re: XML DOM & XPath | ||
| References: | 1 | Groups: | php.xml.dev |
| Request: | Send a blank email to php-xml-dev+get-250@lists.php.net to get a copy of this message | ||
On Mon, 03 Nov 2003 10:53:33 +0000, Ian Williams wrote:
You can do it the same way you did before:
$xml = new DomDocument();
$xml->loadXML($strXml);
$xPath = new DomXPath($xml);
$result = $xPath->query('yourqueryhere');
print_r($result);
NB. This is using php5b2. You can also do XPath queries in PHP4
using the domxml extension
(http://uk.php.net/xpath_new_contextwww.php.net/domxml)
> I have an XML document as a string $strXml, that looks a little like this:
>
> <recordset>
> <row>
> <userid>1</userid>
> <username>Bob</username>
> <password>Rover</username>
> </row>
> <row>
> <userid>2</userid>
> <username>Fred</username>
> <password>Fido</username>
> </row>
> </recordset>
>
> What's the best way to grab a single value from this form? In the past (in
> VB), I have loaded the XML into a DOM Document, and used an XPath query to
> select the data I want, and then bung the output into a string.
>
> Any suggestions?
>
> Thanks
> Ian
--
riot.