Re: (no subject)
Brought to you by:
bs_php,
nigelswinson
From: Peter R. <php...@pe...> - 2004-08-23 15:56:30
|
On Friday 20 Aug 2004 13:11, Jani Pohjanraito wrote: > However, I cannot even overcome the simple first step, displaying the whole > tree. I *can* however access the contents of the single nodes of the tree > (like this: ' $txt = $xpath->getData("article/teksti"); '). > > No matter what I try there's simply "XPath error in XPath.class.php:5813 > The supplied xPath 'root[1]' does not *uniquely* describe a node in the xml > document.Not unique xpath-query, matched 0-times." The code follows: > > I have this simple XML-file that depicts an article: > > <?xml version="1.0" encoding="UTF-8" ?> > <article> > <otsake>Title Here</otsake> > <teksti>Yabba Pala Plah Blah blaa. Gabber gabba yadda wabba. Shaba dada > baba.</teksti> > <pvm>19082004</pvm> > <contact>fa...@ch...</contact> > </article> > > And then I tested Xpath 3.5 with this code: > > require_once("XPath.class.php"); > $xpath = new XPath("vi_articles.xml"); //the xml file above > //Display all the content > $art = $xpath->getData("root[1]"); > echo "<hr>koko artikkeli:<br> $art<hr>"; > .. > > In place of 'root[1]' I also tried '/', '/article', 'article', > 'article[0]', 'article[1]', '/root', '/root[1]' (and several hundred other > variations it seems 8) ) > > What gives? How to get to the whole tree so I can 'echo' it? not sure I understand what you are trying to do. getData() is for getting the contents of a data node. Your <article> node is not a data node. You can do getData("article[1]") but it will be empty. If you want a list of the children of the <article> node, do an evaluate/match on /article[1]/* or whatever; this will return a nodeset array which you can then process with a do-loop or whatever on the individual child nodes, for example, to get their data contents. |