Re: Root[1] vs Root (2)
Brought to you by:
bs_php,
nigelswinson
From: Nigel S. <nig...@us...> - 2002-08-06 22:53:13
|
Ah thanks... Code read: if (sizeOf($xPathSet) !== 1) { return FALSE; } $baseXPath = $xPathSet[>>>1<<<]; And should have read if (sizeOf($xPathSet) !== 1) { return FALSE; } $baseXPath = $xPathSet[0]; Silly off by one error. Should hopefully work now. If not please send .xml and .php so that I can quickly run here and fix. Cheers Nigel =========================== For the most recent version of Php.XPath, and an archive of this list visit: http://www.sourceforge.net/projects/phpxpath ----- Original Message ----- From: "Branko Namestnik" <bra...@in...> To: <php...@li...> Sent: Tuesday, August 06, 2002 11:12 PM Subject: Re: Root[1] vs Root (2) > Thank you for nice explanation, Nigel. I'm also very thankful fur code > modification. > Unfortunately my test shows error. After downloading the latest XPath > from CVS, I tried to use > > $set = $x1->match("//document", "/root/folder[3]"); > > but results have been from whole document, not only from folder[3], > with php error *"Notice*: Undefined offset: 1 in *XPath.class.php* on > line *2126"*. > > Cheers, > Branko > > > Nigel Swinson wrote: > > >>>I've noticed that root absolute path need to be numbered as root[1]: > >>> $set = $x1->match("//document", "/root[1]/folder[3]"); > >>> > >>>In case without [1] after root > >>> $set = $x1->match("//document", "/root/folder[3]"); > >>>have got error: > >>>*XPath error in XPath.class.php:2121* The supplied xPath '//document' > >>>does not *uniquely* describe a node in the xml document. > >>> > >>>Seems strange to me, as root is always the only one. > >>> > >>> > > > >Wherever the class takes an xPathQuery, you can miss out the [] if there is > >only one relevant node, but where the class takes an absoluteXPath, that > >particular argument isn't "pre evaluated" so you have to provide an > >absoluteXPath. "/root" isn't a node in the document, but "/root[1]" is. > >"/root" is an XPath expression (an xPathQuery) that evaluates to precisely > >one node it so happens, so what we can do is to evaluate() on the /root, > >then check that it returns only one node. > > > >Your code will be faster if you supply the [] though, as it means that the > >class does not needlessly have to evaluate the /root XPath expression only > >to find out that there is only one root node. > > > >Never-the-less to make the class easier to use, I've upgraded the second > >parameter of match() for you to an xPathQuery rathar than an absoluteXPath, > >and demand that the xPathQuery evaluate to a single node. > > > >Cheers > > > >Nigel > > > > > > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Phpxpath-users mailing list > Php...@li... > https://lists.sourceforge.net/lists/listinfo/phpxpath-users > |