Re: beginning: importFromString()
Brought to you by:
bs_php,
nigelswinson
From: Peter R. <php...@pe...> - 2003-12-08 11:42:13
|
On Sunday 07 Dec 2003 19:55, darcy w.christ wrote: > $xpath = new XPathEngine($xmlOptions); > > $xpath = $xpath->importFromString("<people><name > id=\"2\">fred</name></people>"); um, not tried this to see what it does, but Import returns true or false, so looks like you set $xpath to true :-) try leaving out "$xpath =" > // i know this is not right - so how to i use the XPath class > methods, once i have > // used XPathEngine? > $result = $xpath->getAttributes('//name[@id=2]','initial'); id is the attribute, 'fred' is the data content of the node. What is 'initial'? I would have thought there were 3 cases: either you have the name and want the id, in which case you use getAttributes for the node with the name you are looking for, or you have the id and want the name, in which case you use getData for the id, or you have neither and want a list, in which case you use match/evaluate and loop through the result. There's an example at the end of XPath.class.php |