(no subject)
Brought to you by:
bs_php,
nigelswinson
From: Jani P. <yj...@ku...> - 2004-08-20 12:11:26
|
I'm very interested in using XPath with my projects to handle XML. So I decided to do some simple testing. 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? Thanks for reading, j |