Thread: Version 3.0 now available!
Brought to you by:
bs_php,
nigelswinson
From: Nigel S. <nig...@us...> - 2002-05-08 00:45:36
|
Well you've all been mighty quiet recently, which is nice in some ways, but hopefully it's not because you hate the class and aren't using it. The project has broken the 4000 downloads barrier in the space of 8 months, so presumably there are still users out there somewhere :o) Anyway version 3.0 is here, and it is 50% faster at reading, 40% faster at writing (at least it is on my home system), and the internal structure has been mashed about to make it much more maintainable, sensible and faster. It's a beta though, and needs to be considered as such, so please don't kill your production sites just yet and do some backing up and testing before you roll it out anywhere. We have a fairly large test harness now, so I think it's fairly sound, but then who out there can guarentee their code has no bugs? Project page and downloads: https://sourceforge.net/projects/phpxpath/ Change log: http://www.carrubbers.org/scripts/php/xpath/Changes.html Documentation: http://www.carrubbers.org/scripts/php/xpath/doc/ Test Harness: http://www.carrubbers.org/scripts/php/xpath/testBench/ Enjoy, :o) Nigel =========================== For the most recent version of Php.XPath, and an archive of this list visit: http://www.sourceforge.net/projects/phpxpath |
From: Philipp L. <le...@hi...> - 2002-05-08 03:05:04
|
From: "Nigel Swinson" <nig...@us...> >.. > Anyway version 3.0 is here, and it is 50% faster at reading, 40% faster at > writing (at least it is on my home system), and the internal structure has > been mashed about to make it much more maintainable, sensible and faster. >.. This is great news. I will replace it on the systems I use it at (namely at http://questml.com and http://outer-court.com/tech/forum.htm ) and of course do some Beta testing. BTW is it normal that e.g. "myElement | myOtherElement" (or maybe ".//myElement | .//myOtherElement") will return the elements not in the order they appear in the XML, but in the order as listed in the XPath-string? I wish they could be listed as appearing in the XML, as this is the result I get from MSXML. Is it not standardized, and up to the XPath-parser to decide the returned order, or simply a PHPXPath bug? I'd really need the above-mentioned in my QML interpreter, and now have to resort to xpath = "./*" .... switch ($elementNodeName...) { case "myElement": ... case "myOtherElement": ... } which then works in the order I expected. (But has little advantage to XML-DOM childNodes...) |
From: Nigel S. <nig...@us...> - 2002-05-09 22:36:07
|
> This is great news. I will replace it on the systems I use it at (namely at > http://questml.com and http://outer-court.com/tech/forum.htm ) and of course > do some Beta testing. > > BTW is it normal that e.g. > "myElement | myOtherElement" > (or maybe ".//myElement | .//myOtherElement") > will return the elements not in the order they appear in the XML, but in the > order as listed in the XPath-string? Hmmm, I'm not sure. > I wish they could be listed as appearing in the XML, as this is the result I > get from MSXML. Is it not standardized, and up to the XPath-parser to decide > the returned order, or simply a PHPXPath bug? Could be. Looking at the XPath spec it says ========================== The primary syntactic construct in XPath is the expression. An expression matches the production Expr. An expression is evaluated to yield an object, which has one of the following four basic types: a.. node-set (an ***unordered*** collection of nodes without duplicates) b.. boolean (true or false) c.. number (a floating-point number) d.. string (a sequence of UCS characters) ========================== So we don't have to guarentee anything at all about the order. If you could locate something for us that says that the way we do it is wrong then we can happily change it. I agree with you that it is probably more useful to be in the doc order. Perhaps what we should do is to have a sort function. It takes a function (An XPath expression?) that will determine which of two nodes are "greater" and bubble sorts the list? Nigel |
From: Peter R. <php...@pe...> - 2002-05-12 12:36:37
|
On Thursday 09 May 2002 23:37, Nigel Swinson wrote: > > > > BTW is it normal that e.g. > > "myElement | myOtherElement" > > (or maybe ".//myElement | .//myOtherElement") > > will return the elements not in the order they appear in the XML, but in the > > order as listed in the XPath-string? > > > I wish they could be listed as appearing in the XML, as this is the > > result > I > > get from MSXML. Is it not standardized, and up to the XPath-parser to > decide > > the returned order, or simply a PHPXPath bug? > > Could be. Looking at the XPath spec it says > > ========================== > The primary syntactic construct in XPath is the expression. An expression > matches the production Expr. An expression is evaluated to yield an object, > which has one of the following four basic types: > a.. node-set (an ***unordered*** collection of nodes without duplicates) > b.. boolean (true or false) > c.. number (a floating-point number) > d.. string (a sequence of UCS characters) > ========================== > > So we don't have to guarentee anything at all about the order. > > If you could locate something for us that says that the way we do it is > wrong then we can happily change it. I agree with you that it is probably > more useful to be in the doc order. hmm, this bit of the xpath spec seems very dubious to me. The data model section of XPath spec goes on at length about document order, and many functions such as preceding, following, first, last etc depend on nodes being in that order. If the Xpath xpression (evaluate in phpxpath terms) doesn't return nodes (i.e. set up the array) in that sequence, how can we use it? The particular case Philipp raises where you have a union is perhaps a special case, as it depends on whether you define 'union' as one result-set followed by another (what it seems phpxpath currently does) or merged into one (as I too think it should do). > Perhaps what we should do is to have a sort function. It takes a function > (An XPath expression?) that will determine which of two nodes are "greater" > and bubble sorts the list? ok if you have a structured-data type of xml file, but if you have a text-document type of node, such as <p>Here are a few examples: <li>first example</li> <li>example no 2</li> <li>a further example</li> and so on</p> How do you sort that, other than in document order? And if you add a further nnn <p> nodes - the norm in document files - how can they be used if not in document order? In what order can the 'nodes' of, say, a Shakespeare play be processed other than the one he wrote?! |
From: Philipp L. <le...@hi...> - 2002-05-08 03:27:43
|
Hmm, I get a corrupted ZIP file message trying to unpack the downloads (I tried different servers provided). WinZip alerts me that 400 something bytes are missing... |
From: Nigel S. <nig...@us...> - 2002-05-08 10:55:46
|
Damn. I'd uploaded it as ascii. Ooops.. Please try again now. Both packages should be fine now. If not then drop me a mail again. =========================== For the most recent version of Php.XPath, and an archive of this list visit: http://www.sourceforge.net/projects/phpxpath |
From: Philipp L. <le...@hi...> - 2002-05-08 18:34:07
|
I successfully downloaded the new version and replaced version 2.2. However, my forum now doesn't work anymore. It doesn't cause an error, it just returns an array of count 0. This is my XPathQuery, which I pass to ->match ... posts/post[@replyTo = '0'] on the document-root of data like this, submitted via ->importFromString: <?xml version="1.0"?> <posts> <!-- "about" section --> <post id="43" replyTo="0"> <title>Question</title> <author>xyz</author> <text>....</text> </post> <post id="45" replyTo="43"> <title>Re: Question</title> <author>abc</author> <text>....</text> </post> <!-- ... many more posts --> </posts> The forum overview does still work the same (it checks for the latest post and latest author). Am I doing something wrong or is this a bug in the 3.0 beta version? |
From: Nigel S. <nig...@us...> - 2002-05-09 23:58:54
|
> I successfully downloaded the new version and replaced version 2.2. > However, my forum now doesn't work anymore. It doesn't cause an error, it > just returns an array of count 0. > > This is my XPathQuery, which I pass to ->match ... > > posts/post[@replyTo = '0'] > > on the document-root of data like this, submitted via ->importFromString: > > <?xml version="1.0"?> > <posts> > > <!-- "about" section --> > > <post id="43" replyTo="0"> > <title>Question</title> > <author>xyz</author> > <text>....</text> > </post> > > <post id="45" replyTo="43"> > <title>Re: Question</title> > <author>abc</author> > <text>....</text> > </post> > > <!-- ... many more posts --> > > </posts> > > The forum overview does still work the same (it checks for the latest post > and latest author). > Am I doing something wrong or is this a bug in the 3.0 beta version? Well done! You've found the first 3.0 bug. If you get the latest version out of cvs then it should work. Have added a set of tests to the test harnes so that this bug won't appear in future releases. Cheers, Nigel |
From: Peter R. <php...@pe...> - 2002-05-10 11:21:14
|
On Friday 10 May 2002 1:00, Nigel Swinson wrote: > Well done! You've found the first 3.0 bug. If you get the latest version > out of cvs then it should work. Have added a set of tests to the test > harnes so that this bug won't appear in future releases. downloaded the cvs version, but it looks like getData will no longer fetch attributes, either in the @ or the attribute:: notation. I have changed my scripts to use getAttributes instead, but is this deliberate or a bug? When I ran my old scripts - using getData - it produced errors for the implode line immediately following. Shouldn't === read == ? The errors went away when I changed this! |
From: Nigel S. <nig...@us...> - 2002-05-12 01:27:14
|
> downloaded the cvs version, but it looks like getData will no longer fetch > attributes, either in the @ or the attribute:: notation. I have changed my > scripts to use getAttributes instead, but is this deliberate or a bug? > > When I ran my old scripts - using getData - it produced errors for the > implode line immediately following. Shouldn't === read == ? The errors went > away when I changed this! Not deliberate, so I suppose you could class it as a "bug", I prefer the term "ommision" :o) Anyway I've coded this in now, so getData() can be used to get the data of an attribute, however getAttributes() is faster, and I would recommend it if you know that you are getting from an attribute and not a node. I've added a test to the test harness so that future releases don't suffer from this numpty attack. The change is in CVS if you can't wait for it to be released. Will probably wait several more weeks before 3.1 Please keep a close eye out for similar bugs relating to attributes. The test harness that we've built uses DOM test data (the DOM-TS project from w3c). In the DOM world, attributes are quite different entities to Nodes, so the coverage in the Php.XPath functions where attributes and nodes are considered the same kind of entities is poor. Cheers, Nigel |
From: Philipp L. <le...@hi...> - 2002-05-10 17:54:34
|
From: "Nigel Swinson" <nig...@us...> > > Well done! You've found the first 3.0 bug. If you get the latest version > out of cvs then it should work. Have added a set of tests to the test > harnes so that this bug won't appear in future releases. > Sorry, still doesn't work... I use a whole lot of getData, is it causing trouble? (I read something from Peter Robins along the lines.) |
From: Nigel S. <nig...@us...> - 2002-05-13 18:15:38
|
> From: "Nigel Swinson" <nig...@us...> > > Let me know if that other getData() fix doesn't solve your problem. Send > > some examples and stuff and I'll try to locate the bug you are getting. > > Think it's likely that it is your bug though. > > > > Might be it's my bug, but the 2.2 version works good. Well I attach the > forum. It's tested on Win 98 PWS with the results described below. > What you should do is run the index.php. Now click on "current threads" of > the top most category. > The result is many threads, and I echo the XPath: > XPath: "posts/post[@replyTo = '0']" result-count: 7 > > This was version 2.2. > Now go rename "XPath.class.php" to "old_XPath.class.php" and rename > "new_XPath.class.php" to "XPath.class.php" (which is from the latest release > you mentioned in the list). Suddenly no more posts are shown, as the result > on "current threads" is: > XPath: "posts/post[@replyTo = '0']" result-count: 0 > > (Please note that there's a single function "getAttribute" that I added to > both the old and new class. It's not accessed in this part of the problem, > but you can find it searching for "Phil".) Ok I just loaded your forum, and you aren't using the latest version from CVS. I did a diff between your version of Php.XPath and the latest and there were several bug fixes that were in mine but not in yours, but add to that you had your getAttribute function. When I made it use the latest version by adding your getAttribute function it all worked fine :o) So if you visit http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/phpxpath/ and navigate your way to the development version, you can get the fix without waiting for 3.1 Cheers, Nigel |
From: Philipp L. <le...@hi...> - 2002-05-12 13:11:05
|
From: "Peter Robins" <php...@pe...> >.. > How do you sort that, other than in document order? > And if you add a further nnn <p> nodes - the norm in document files - how can > they be used if not in document order? In what order can the 'nodes' of, say, > a Shakespeare play be processed other than the one he wrote?! >.. Yes. And also I could imagine a dozen other cases, except my current one where I'd need it. Imagine you want to build a table-of-contents for an XHTML page. The most reasonable expression to me seems to be: //h1 | //h2 | //h3 | //h4 | //h5 | //h6 and then process this e.g. building a nested list. It's very important here that an h2 following an h1 in the original document can be understood as belonging to this h1 as a sub-heading. (I do the above in an MSXML4-based Content Management System.) |
From: Nigel S. <nig...@us...> - 2002-05-13 18:07:48
|
> > How do you sort that, other than in document order? > > And if you add a further nnn <p> nodes - the norm in document files - how > can > > they be used if not in document order? In what order can the 'nodes' of, > say, > > a Shakespeare play be processed other than the one he wrote?! > >.. > > Yes. And also I could imagine a dozen other cases, except my current one > where I'd need it. > Imagine you want to build a table-of-contents for an XHTML page. > The most reasonable expression to me seems to be: > //h1 | //h2 | //h3 | //h4 | //h5 | //h6 > and then process this e.g. building a nested list. > It's very important here that an h2 following an h1 in the original document > can be understood as belonging to this h1 as a sub-heading. > (I do the above in an MSXML4-based Content Management System.) Ok I totally agree that doc order is the most useful, but how about this scenario: <?xml version="1.0" ?> <XmlDatabase> <Sermons> <Sermon RecordId="1"> <Date>1-Jan-92</Date> <CatalogueNo>BRJ 01</CatalogueNo> <Speaker>Brian Russell-Jones</Speaker> </Sermon> <Sermon RecordId="3"> <Date>1-Jan-92</Date> <CatalogueNo>WS 01</CatalogueNo> <Speaker>Wayne Sutton</Speaker> </Sermon> <Sermon RecordId="4"> <Date>1-Mar-92</Date> <CatalogueNo>BRJ 04</CatalogueNo> <Speaker>Brian Russell-Jones</Speaker> </Sermon> <Sermon RecordId="5"> <Date>1-Apr-92</Date> <CatalogueNo>WS 02</CatalogueNo> <Speaker>Wayne Sutton</Speaker> </Sermon> </Sermons> </XmlDatabase> You want to search for all the sermons, but have them sorted by date, catalogue, or speaker. If sorted by date you get: /XmlDatabase[1]/Sermon[1] /XmlDatabase[1]/Sermon[2] /XmlDatabase[1]/Sermon[3] /XmlDatabase[1]/Sermon[4] If sorted by speaker you get: /XmlDatabase[1]/Sermon[1] /XmlDatabase[1]/Sermon[3] /XmlDatabase[1]/Sermon[2] /XmlDatabase[1]/Sermon[4] etc. What I'll try to do is to make doc order the default output, but there may still be occasions where sorting the data by some other criteria is useful. Nigel |
From: Philipp L. <le...@hi...> - 2002-05-13 19:15:03
|
From: "Nigel Swinson" <nig...@us...> >.. > What I'll try to do is to make doc order the default output, but there may > still be occasions where sorting the data by some other criteria is useful. >.. Oh, that's definitely totally useful to have that as an option. In fact, I spend hours biting my knee because the MSXML won't let me produce any kind of sorted output. In XSLT this seems to come naturally. |
From: Nigel S. <nig...@us...> - 2002-05-13 20:47:10
|
> What I'll try to do is to make doc order the default output, but there may > still be occasions where sorting the data by some other criteria is useful. Ok the default order for the results is now doc order. Sorting by other means probably isn't too difficult anyway, as you can use the usort() function that takes a callback of two elements that you can then write your own function to compare elements with. So you would do something like this (haven't tested this...): $XPathObj = new XPath; function cmp($a, $b) { global $XPathObj; $sA = $XPathObj->getData($a.'/SomewhereElse'); $sB = $XPathObj->getData($b.'/SomewhereElse'); return (strcmp($sA, $sB)); } $aPaths = $XPathObj->evaluate('something or other'); usort($aPaths, "cmp"); Nigel |
From: Peter R. <php...@pe...> - 2002-05-14 10:29:07
|
> > Imagine you want to build a table-of-contents for an XHTML page. > > The most reasonable expression to me seems to be: > > //h1 | //h2 | //h3 | //h4 | //h5 | //h6 > > and then process this e.g. building a nested list. can you not use starts-with("h") function to return them all in one node-set? |
From: Philipp L. <le...@hi...> - 2002-05-14 18:54:18
|
From: "Peter Robins" <php...@pe...> > > > Imagine you want to build a table-of-contents for an XHTML page. > > > The most reasonable expression to me seems to be: > > > //h1 | //h2 | //h3 | //h4 | //h5 | //h6 > > > and then process this e.g. building a nested list. > > can you not use starts-with("h") function to return them all in one node-set? > Nope, as that might also return "html", "head", and "hr". (I could use a little for-loop and build the string, but why bother? XHTML is restricted to 6 levels of headings.) |
From: Peter R. <php...@pe...> - 2002-05-14 10:29:04
|
On Monday 13 May 2002 21:48, Nigel Swinson wrote: > > Ok the default order for the results is now doc order. Sorting by other > means probably isn't too difficult anyway, as you can use the usort() > function that takes a callback of two elements that you can then write your > own function to compare elements with. wouldn't disagree with you Nigel, but the problem is surely where there is no element to sort by. If you have in your xml source <a><b><c><a><b><c><b><a> and you say match("//a | //b"), it should return a b a b b a, but it doesn't; it returns the <a>s first, then the <b>s, i.e. a a a b b b. This is wrong, as you are losing information, namely the document order. Of course, as you say, if you want it sorted in some particular sequence, then you can do so using PHP functions. This is similar to the problem we had with the original phpxml retrieving parts of text nodes in the wrong order: once the program has sorted it like this, there is no criteria by which you can get it back to the original sequence. |
From: J. C. <jan...@im...> - 2002-05-14 12:52:34
|
Hello, I would like to use the new Version but I got problems when changing something. Here is a simple example: ====================================================== <? require_once("XPath.class.php"); //new //require_once("XPath.class_V2.php"); //old $xmlfile="xmlfile.xml"; echo "[new XPath]<BR>"; $xpath = new XPATH($xmlfile); echo "[appenChild \"TEST\" to \"root[1]\"]<BR>"; $child=$xpath->appendChild("/root[1]","TEST"); echo "[replaceData \"TEST\"]<BR>"; $xpath->replaceData($child,"TEST"); echo "[exportToFile] <BR>"; $xpath->exportToFile($xmlfile,'','<?xml version="1.0" encoding="iso-8859-1" standalone="yes"'.'?'.'>'); ?> ====================================================== This code gives me this output: ====================================================== [new XPath] [appenChild "TEST" to "root[1]"] XPath error in XPath.class.php:4524 XPath error in XPath.class.php:1454. Message: In importFromString(): XML error in given string on line 1 column 0. Reason:syntax error [replaceData "TEST"] [exportToFile] PHP Warning: Undefined variable: PHP_SELF in C:\Server-Entwicklung-V2\imeso\web\Administration\data\XPath.class.php on line 4698 ====================================================== The XML Code is: ====================================================== <?xml version="1.0" encoding="iso-8859-1" standalone="yes"?><root> </root> ====================================================== When I use the old version it works nice so I think it might be a bug. Any help? (The warning is no problem - I normally comment that section at line 4698) Cheers Jan |
From: Sam B. <bs...@us...> - 2002-05-14 16:03:50
|
Hi Jan, It's not a bug. appendChild() and replaceData() need a valid XML string as second parameter: E.g. $xpath->appendChild("/root[1]","<TEST/>"); The main advantage (and reason) is that it's now possable to append any valid XML (not just a single child) to the doc. E.g. $xPath->appendChild("/root[1]"', '<CC> bla bla <DD dd="d"> foo</DD> <EE/> </CC>'); The return value of appendChild() and replaceData() are currently bool. But it would make sens if they would return the abs. Xpath string of the inserted node. (Something to do). -- Sam Blum <bs...@us...> =========================== For the most recent version of PHP.XPath and an archive of this list visit: http://sourceforge.net/projects/phpxpath |
From: Nigel S. <nig...@us...> - 2002-05-14 20:45:31
|
> The return value of appendChild() and replaceData() are currently bool. But > it would make sens if they would return the abs. Xpath string of the > inserted node. (Something to do). Actually it is the XPath of the inserted node. I change this recently but didn't update the header.... oops :o) Nigel |
From: Nigel S. <nig...@us...> - 2002-05-14 18:51:03
|
> > Ok the default order for the results is now doc order. Sorting by other > > means probably isn't too difficult anyway, as you can use the usort() > > function that takes a callback of two elements that you can then write your > > own function to compare elements with. > > wouldn't disagree with you Nigel, but the problem is surely where there is no > element to sort by. If you have in your xml source > <a><b><c><a><b><c><b><a> > and you say match("//a | //b"), it should return a b a b b a, but it doesn't; > it returns the <a>s first, then the <b>s, i.e. a a a b b b. This is wrong, as > you are losing information, namely the document order. Of course, as you say, > if you want it sorted in some particular sequence, then you can do so using > PHP functions. Yeah it used to return aaabbb, but as I said "the default order for the results is now doc order". So as of CVS file version 1.86, the order returned will be ababba. If you want to sort by some other criteria, other than doc order, then you can use usort(). Hopefully that meets the needs... Nigel |
From: Peter R. <php...@pe...> - 2002-05-15 17:20:09
|
On Tuesday 14 May 2002 19:52, Nigel Swinson wrote: > Yeah it used to return aaabbb, but as I said "the default order for the > results is now doc order". So as of CVS file version 1.86, the order > returned will be ababba. ah yes, so it does. sorry, misunderstood you |