phpxpath-users Mailing List for Php.XPath (Page 5)
Brought to you by:
bs_php,
nigelswinson
You can subscribe to this list here.
2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(346) |
Nov
(8) |
Dec
(21) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2002 |
Jan
(30) |
Feb
(13) |
Mar
|
Apr
(3) |
May
(70) |
Jun
(26) |
Jul
(48) |
Aug
(22) |
Sep
(1) |
Oct
(4) |
Nov
|
Dec
|
2003 |
Jan
(3) |
Feb
(3) |
Mar
(11) |
Apr
(3) |
May
(4) |
Jun
(3) |
Jul
(2) |
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
(2) |
2004 |
Jan
(4) |
Feb
(2) |
Mar
(2) |
Apr
(2) |
May
|
Jun
|
Jul
(12) |
Aug
(8) |
Sep
(2) |
Oct
(2) |
Nov
(3) |
Dec
|
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
(2) |
Sep
|
Oct
(1) |
Nov
(1) |
Dec
|
2006 |
Jan
(3) |
Feb
(7) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
From: Thomas P. N. <as...@mi...> - 2002-08-07 07:39:59
|
Hi again, first off I want to thank you Nigel for the tremendous effort you put into this and I want you to know that it's greatly appreciated. Keep up the good work. Just to comment on Daniels problems: > XPath error in XPath.class.php:1586 In importFromString(): XML error > in given string on line 1 column 0. Reason:syntax error I get the same sort of error - that is varying 'XPath.class.php:####' errors followed by the 'line 1 column 0' hint. One further problem is in the code below. I know it's a bit lengthy - I hope you won't mind it. - Begin code ----- $myindex = new xpath(); $myindex->setSkipWhiteSpaces($onOff=TRUE); $myindex->setXmlOption('XML_OPTION_TARGET_ENCODING', 'UTF-8'); $myindex->importFromString("<searchindex/>"); $searchindex = $myindex->evaluate("searchindex"); foreach ($resultarray as $page => $pagename) { $xmlpage = $myindex->appendChild("searchindex","<$page/>"); foreach ($pagename as $itemkey => $itemvalue) { $myitem = $myindex->appendChild($xmlpage,"<item/>"); } } $myindex->exportToFile("../search_index.xml"); - End code ----- The problem is, that the child in the line '$myitem = $myindex->appendChild($xmlpage,"<item/>");' doesn't seem to work. Now, if placed outside the foreach loop it does work, which strikes me as odd. I've tried with manual as well as automatic reindexing, which doesn't seem to have an influence. I am presented with a blank screen when running the script - no error messages. Thank you very much for your time. Sincerely, Thomas |
From: Branko N. <bra...@in...> - 2002-08-06 23:58:35
|
Works! Thank you! Branko Nigel Swinson wrote: >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 >> >> >> > > > >------------------------------------------------------- >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 > > > |
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 > |
From: Branko N. <bra...@in...> - 2002-08-06 22:11:43
|
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 > > > |
From: Nigel S. <nig...@us...> - 2002-08-06 20:04:25
|
> > 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 |
From: Branko N. <bra...@in...> - 2002-08-06 18:35:02
|
> 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. > > Branko |
From: Branko N. <bra...@in...> - 2002-08-06 18:12:32
|
I've noticed that root absolute path need to be numbered as root[1]: $set = $x1->match("//document", "/root[1]/folder"); In case without [1] after root $set = $x1->match("//document", "/root/folder"); 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. Branko |
From: Daniel L. <inf...@aj...> - 2002-08-06 15:20:49
|
Bonjour Nigel, Le mardi 6 ao=FBt 2002 =E0 16:23:01, vous =E9criviez : NS> What happens if you run Junk.php? All is good ! It's me, I modify only the first call to =ABappendChild=BB, and let the others with a string. I focalize on the beginning of my code. Excuse-me ;-) Thanks for this great job. --=20 Cordialement, Daniel mailto:inf...@aj... ---------- Support-Assistance PHP/MySql de =ABInternet Pour Tous=BB=20 http://www.i-p-t.com.fr/ :::XML/XSLT - Sablotron::: -- |
From: Nigel S. <nig...@us...> - 2002-08-06 14:25:59
|
Odd, I just tested again and it works. I attach my .php file that I'm using to test, and the output it produces: What happens if you run Junk.php? Looking at the errors you are getting returned, something odd is up, because it is calling importFromString() BEFORE it has reached the appendChild() call. :o/ 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: "Daniel Lucazeau" <inf...@aj...> To: <php...@li...> Sent: Tuesday, August 06, 2002 2:57 PM Subject: Re[2]: Am I a doofus? Bonjour Nigel, Le mardi 6 août 2002 à 02:19:52, vous écriviez : NS> $myroot = $myxpath->appendChild("","<superroot/>"); NS> However I just tried this and it didn't work, because the super root hadn't NS> been setup, so this is a bug for which I thank you kindly for reporting :o) NS> I've just implemented a change so that you can do this now. You'll find it NS> in CVS if you can't wait for the next release, or you would like to do some NS> testing :o) I need the same feature so I try the CVS version 1.111, but without success. I try : $xml = new XPath(); $rootPath = $xml->appendChild( "", "<xml/>"); And I get : XPath error in XPath.class.php:1586 In importFromString(): XML error in given string on line 1 column 0. Reason:syntax error XPath error in XPath.class.php:5155 XPath error in XPath.class.php:1586. Message: In importFromString(): XML error in given string on line 1 column 0. Reason:syntax error -- Cordialement, Daniel mailto:inf...@aj... ---------- Support-Assistance PHP/MySql de «Internet Pour Tous» http://www.i-p-t.com.fr/ :::XML/XSLT - Sablotron::: -- ------------------------------------------------------- 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 |
From: Daniel L. <inf...@aj...> - 2002-08-06 13:57:51
|
Bonjour Nigel, Le mardi 6 ao=FBt 2002 =E0 02:19:52, vous =E9criviez : NS> $myroot =3D $myxpath->appendChild("","<superroot/>"); NS> However I just tried this and it didn't work, because the super root = hadn't NS> been setup, so this is a bug for which I thank you kindly for reporti= ng :o) NS> I've just implemented a change so that you can do this now. You'll f= ind it NS> in CVS if you can't wait for the next release, or you would like to d= o some NS> testing :o) I need the same feature so I try the CVS version 1.111, but without succe= ss. I try : $xml =3D new XPath(); $rootPath =3D $xml->appendChild( "", "<xml/>"); And I get : XPath error in XPath.class.php:1586 In importFromString(): XML error in given string on line 1 column 0. Reason:syntax error XPath error in XPath.class.php:5155 XPath error in XPath.class.php:1586. Message: In importFromString(): XML error in given string on line 1 column 0. Reason:syntax error --=20 Cordialement, Daniel mailto:inf...@aj... ---------- Support-Assistance PHP/MySql de =ABInternet Pour Tous=BB=20 http://www.i-p-t.com.fr/ :::XML/XSLT - Sablotron::: -- |
From: Nigel S. <nig...@us...> - 2002-08-06 00:22:50
|
> I've noticed a lot of differences in migrating from v2.2 to v3.3. :o( > For instance, this was possible in v2.2: > > $myxpath = new xpath(); > $myroot = $myxpath->appendChild("","superroot"); Ah... all the functions like importFromString() and appendChild() now take an xml string rather than just a node name, so you need to do: $myroot = $myxpath->appendChild("","<superroot/>"); However I just tried this and it didn't work, because the super root hadn't been setup, so this is a bug for which I thank you kindly for reporting :o) I've just implemented a change so that you can do this now. You'll find it in CVS if you can't wait for the next release, or you would like to do some testing :o) > .. but not in v3.3. Furter, in v2.2 a query through evaluate() to an > unique xpath would produce a string, whereas v3.3 produces an array > There are workarounds for it, but none the less - I've had numerous > encounters of the odd kind to which I can seem to find no obvious solution. In having a closer look at the XPath spec, the "top level" syntactical element is an "Expr", which.... http://www.w3.org/TR/xpath#section-Introduction "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) " Clearly the intention wasn't to break anyone's code, but in order to support XPath properly (in it's recursive nature), you could now get a string, a number, a boolean or a node set (an array) as the result from match()/evaluate(). So if you have an xpath expression that is designed to "match" a node, then it really matches a node set that contains only one node, and hence it comes back to you in an array :o( You could always build a wrapper round match() that would convert an array with one element into just one string if that would make migration easier? > Can anyone tell me if I can find documentation on the differences in > implementation? Or, preferably; different examples on usage? I'll be more than happy to show you how to do what you need to do with version 3, sadly there is no definitive differences document. We worked fairly hard to minimise any public interface differences, as we know how distruptive they are to your code, and I was under the impression that the differences were slight, but then perhaps not... You could view the cvs history (which is fairly lenghty between 2.2 and 3.2), or do a diff between the .php files, but sadly nothing better than that is on offer. > I suspect being a doofus, but I'd really like to get this sorted out. Not a doofus at all :o) Let me/us know if you need anymore bug fixes or usage hints. Nigel |
From: Thomas P. N. <as...@mi...> - 2002-08-05 08:11:25
|
Hi list, I've noticed a lot of differences in migrating from v2.2 to v3.3. For instance, this was possible in v2.2: $myxpath = new xpath(); $myroot = $myxpath->appendChild("","superroot"); .. but not in v3.3. Furter, in v2.2 a query through evaluate() to an unique xpath would produce a string, whereas v3.3 produces an array There are workarounds for it, but none the less - I've had numerous encounters of the odd kind to which I can seem to find no obvious solution. Can anyone tell me if I can find documentation on the differences in implementation? Or, preferably; different examples on usage? I suspect being a doofus, but I'd really like to get this sorted out. Thank you for any help in advance. Sincerely, Thomas Pilgaard |
From: Kim L. v. <lv...@ra...> - 2002-07-24 23:04:43
|
Hi Try this, it works fine for me $content = parent::exportAsXml(); $content = preg_replace("/\s*(\r\n|\n|\r)\s*/i","",$content); Regards Kim ----- Original Message ----- From: <php...@li...> To: <php...@li...> Sent: Thursday, July 25, 2002 5:36 AM Subject: Phpxpath-users digest, Vol 1 #113 - 1 msg > Send Phpxpath-users mailing list submissions to > php...@li... > > To subscribe or unsubscribe via the World Wide Web, visit > https://lists.sourceforge.net/lists/listinfo/phpxpath-users > or, via email, send a message with subject or body 'help' to > php...@li... > > You can reach the person managing the list at > php...@li... > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Phpxpath-users digest..." > > > Today's Topics: > > 1. Re: Files unformatted (Nigel Swinson) > > --__--__-- > > Message: 1 > From: "Nigel Swinson" <nig...@us...> > To: "Jens Habermann" <Jen...@we...> > Cc: <php...@li...> > Subject: Re: Files unformatted > Date: Wed, 24 Jul 2002 00:35:30 +0100 > > > The fourth option is what i want! Import without skipping whitespaces and > > export with skipping whitespaces. Then he keeps the linebreaks. But if i > > open the file again and export it with skipped whitespaces again i get > > something like this: > > > > <?xml version="1.0"?> > > > > <aaa> > > > > <bbb>This is > > a text > > with linebreaks!</bbb> > > > > </aaa> > > > > And one mor time it looks like this: > > > > <?xml version="1.0"?> > > > > > > <aaa> > > > > > > <bbb>This is > > > > a text > > > > with linebreaks!</bbb> > > > > > > </aaa> > > > > And so on...so what is needed is an option that pretty prints the xml > > structure without using the trim function on the content of the texts. > This > > fourth possibility seems to do that but if you use it several times on a > > file it becmes unreadable again like i described above. > > > > The attached example should convince you that this is a bug. The > example.php > > only opens the file sets SkopWhitespace and outputs the file again. The > > problem is that the pretty printed file becomes unreadable after a few > > times. > > I see what you are trying to do now, but this doesn't convince me that it is > a bug, it's a request for enhancement. The class is designed so that you > are either skipping whitespace, or you are not. If you repeatedly > import/export a file with this setting in either state, then the XML file > will not "grow". If it did, then that would be a bug. If you parse in and > keep whitespace, then write out in the other mode, then you are pushing the > "skip whitespace" feature past what it was designed to support. > > I'm not sure why these line breaks are so important to you, but line breaks > and whitespace in XML files is meant to have no meaning other than > aesthetics, so we provide an option so that you either do your own > formatting because your whitespace has meaning or you don't like the way we > do it (skip white spaces off), or you let the class do the formatting for > you (skip white spaces on). > > http://www.w3.org/TR/2000/REC-xml-20001006#sec-white-space > > So you want a mode where skipWhiteSpaces won't junk whitespace intrernally > in the text data of an element? It will preserve all tabs, newlines, and > spaces, and junk them only if the entire textual content is whitespace, and > ltrim() and rtrim() all other entries? If there is a general desire for > such a feature to be implemented then I might have a go, but as I have no > need for it, I can't see me looking into this with any kind of priority. > > If you want to "play" with this feature yourself, then the function you want > to modify is: > > function _handleCharacterData($parser, $text) { > if ($this->parsInCData >0) $text = $this->_translateAmpersand($text, > $reverse=TRUE); > > if ($this->bDebugXmlParse) echo "Handling character data: > '".htmlspecialchars($text)."'<br>"; > if ($this->parseSkipWhiteCache AND !empty($text) AND > !$this->parsInCData) { > HERE >>> // Special case CR. CR always comes in a separate data. Trans. > it to '' or ' '. > HERE >>> // If txtBuffer is already ending with a space use '' > otherwise ' '. > $bufferHasEndingSpace = (empty($this->parsedTextLocation) OR > substr($this->parsedTextLocation, -1) === ' ') ? TRUE : FALSE; > if ($text=="\n") { > $text = $bufferHasEndingSpace ? '' : ' '; > } else { > if ($bufferHasEndingSpace) { > $text = ltrim(preg_replace('/\s+/', ' ', $text)); > } else { > $text = preg_replace('/\s+/', ' ', $text); > } > } > if ($this->bDebugXmlParse) echo "'Skip white space' is ON. reduced to > : '" .htmlspecialchars($text) . "'<br>"; > } > $this->parsedTextLocation .= $text; > } > > If you come up with something that works quite well then if you send the > change in then we'll look into incorporating it into the main branch. > > Cheers, > > Nigel > > > ----- Original Message ----- > > From: "Nigel Swinson" <nig...@us...> > > To: "Jens Habermann" <Jen...@we...> > > Cc: <php...@li...> > > Sent: Tuesday, July 23, 2002 12:23 PM > > Subject: Re: Files unformatted > > > > > > > Ok I ran your script and see the same output, so I'm glad to say that > this > > > isn't a freak issue that won't "travel". :o) > > > > > > Using the SkipWhitespaces option, and the string you are inputing I can > > get: > > > > > > import without export without > > > > > > <?xml version="1.0"?> > > > <aaa><bbb>This is > > > a text > > > with linebreaks!</bbb></aaa> > > > > > > import with export without (Your example was missing this one...) > > > > > > <?xml version="1.0"?> > > > <aaa><bbb>This is a text with linebreaks!</bbb></aaa> > > > > > > import with export with (This is the one you labelled "buggy") > > > > > > <?xml version="1.0"?> > > > <aaa> > > > <bbb>This is a text with linebreaks!</bbb> > > > </aaa> > > > > > > import without export with > > > > > > <?xml version="1.0"?> > > > <aaa> > > > <bbb>This is > > > a text > > > with linebreaks!</bbb> > > > </aaa> > > > > > > Which seems to be all four possible options. Will none of these do you? > > If > > > not then what do you want? :o/ > > > > > > 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: "Jens Habermann" <Jen...@we...> > > > To: "Nigel Swinson" <nig...@us...> > > > Sent: Monday, July 22, 2002 11:59 PM > > > Subject: Re: Files unformatted > > > > > > > > > > OK here it is :) > > > > > > > > Ive written a little example which outputs 3 different xml files. > Inside > > > the > > > > example.php i described the problem. > > > > > > > > The output files as i get them are included too. Take a look at them > > > before > > > > starting the example.php to realise the difference between them. I > think > > > you > > > > will get the same output as iam but maybe you wont believe me but your > > > eyes > > > > :) > > > > > > > > ----- Original Message ----- > > > > From: "Nigel Swinson" <nig...@us...> > > > > To: "Jens Habermann" <Jen...@we...> > > > > Sent: Tuesday, July 23, 2002 12:13 AM > > > > Subject: Re: Files unformatted > > > > > > > > > > > > > > Ok here is an example: > > > > > > > > > > > > <aaa>This is > > > > > > > > > > > > a text > > > > > > > > > > > > that has line breaks > > > > > > </aaa> > > > > > > > > > > > > if i toggle whitespace to TRUE the output is: <aaa>This is a text > > that > > > > has > > > > > > line breaks</aaa> > > > > > > > > > > > > What ive found out so far is that the trim function of php also > > > deletes > > > > > > linebreaks ("\n") what seems to be the problem... > > > > > > > > > > > > So i have to choose if i want to have pretty printed text without > > > > > linebreaks > > > > > > or an unreadable chunk with linebreaks :) > > > > > > > > > > > > I have included another variable to the PHP.XPath class called > > > > > > $prettyPrinted. At the moment im looking for all the places where > > the > > > > > class > > > > > > formats the text and write some new lines which are checking for a > > > true > > > > > > $prettyPrinted variable and then do the same as skipWhitespace des > > > > without > > > > > > deleting my linebreaks :) > > > > > > > > > > Well good luck then :o) > > > > > > > > > > If you want me to help you, then I have to be able to reproduce the > > > issue > > > > > locally, which means me running EXACTLY the same .php and .xml input > > and > > > > > then comparing the generated output (html? xml?). I need more than > > > just > > > > an > > > > > example of xml with a paragraph describing the operation. I need to > > be > > > > able > > > > > to copy a couple of attachments to a folder, point my browser at the > > php > > > > > page, and then examine the results. :o) > > > > > > > > > > Sounds like you are happy sorting it out on your own :o). My only > > > concern > > > > > (for you) is that your changes aren't going to make it into the main > > > > branch, > > > > > which means you are gonna have to keep re-applying them.... > > > > > > > > > > Nigel > > > > > > > > > > > > > > > > > > > --__--__-- > > _______________________________________________ > Phpxpath-users mailing list > Php...@li... > https://lists.sourceforge.net/lists/listinfo/phpxpath-users > > > End of Phpxpath-users Digest > |
From: Sam B. <bs...@us...> - 2002-07-24 22:20:48
|
Hi Nigel, Hi Jens, I've been following the correspondence of you 2 and somehow have the feeling that Jens is not trying to do something special. He's just doing it in the wrong sequence and is unaware of the it (as I will show below). And Nigel is assuming that Jens wants to do it in that sequence and is unaware that Jens just made a mistake. So what do I mean: It has to do with the option "skip white spaces" and beautifying the XML output. First you must know that when "skip white spaces" is set to TRUE, PHP.XPath always beautified the exported XML because we can safely assume that adding spaces and line brakes to the output will not change the XML content (otherwise PHP.XPath would not be allowed to skip them in the first place). Some time in Php.XPath V2.x I introduced this "skip white spaces" feature and set it the default to TRUE. Now in V3.x it default is set to FALSE.. (Mainly because it was using up to much CPU). Now you can turn it on again BUT you must do it before you IMPORT the XML; it's late to turn it on before you export and will cause the funny output Jens toled about. Here is a sample code that will show you that V3 works as V2 and also shows the effect Jens has when setting "skip white spaces" to late. Hope this will solve the "missunderstanding" ---------------------------------------------------------------------------- <? include('../XPath.class.php'); $head = '<?xml version="1.0"?>'; $xml_input=<<<EOD $head <aaa> <bbb>This is a text with linebreaks!</bbb> </aaa> EOD; echo '<hr>This is the XML given:<hr><pre>'; echo htmlspecialchars($xml_input); echo '</pre>'; # ============================================================================ $xPath =& new XPath; // In V3 skip white spaces has to be turned on (used to be on by default) $xPath->setSkipWhiteSpaces(TRUE); $xPath->importFromString($xml_input); echo '<hr>This is the XML after import with "skip white spaces" set to <strong>ON</strong>:<hr><pre>'; echo $xPath->exportAsHtml(); echo '</pre>'; # ============================================================================ $xPath->reset(); $xPath->setSkipWhiteSpaces(FALSE); $xPath->importFromString($xml_input); echo '<hr>This is the XML after import with "skip white spaces" set to <strong>OFF</strong>:<hr><pre>'; echo $xPath->exportAsHtml(); echo '</pre>'; # ============================================================================ $xPath->reset(); $xPath->importFromString($xml_input); $xPath->setSkipWhiteSpaces(TRUE); echo '<hr>This is what happens if you turn on "skip white spaces" to late !! (After import):<hr><pre>'; echo $xPath->exportAsHtml(); echo '</pre>'; ?> ---------------------------------------------------------------------------- -- 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-07-23 23:38:43
|
> The fourth option is what i want! Import without skipping whitespaces and > export with skipping whitespaces. Then he keeps the linebreaks. But if i > open the file again and export it with skipped whitespaces again i get > something like this: > > <?xml version="1.0"?> > > <aaa> > > <bbb>This is > a text > with linebreaks!</bbb> > > </aaa> > > And one mor time it looks like this: > > <?xml version="1.0"?> > > > <aaa> > > > <bbb>This is > > a text > > with linebreaks!</bbb> > > > </aaa> > > And so on...so what is needed is an option that pretty prints the xml > structure without using the trim function on the content of the texts. This > fourth possibility seems to do that but if you use it several times on a > file it becmes unreadable again like i described above. > > The attached example should convince you that this is a bug. The example.php > only opens the file sets SkopWhitespace and outputs the file again. The > problem is that the pretty printed file becomes unreadable after a few > times. I see what you are trying to do now, but this doesn't convince me that it is a bug, it's a request for enhancement. The class is designed so that you are either skipping whitespace, or you are not. If you repeatedly import/export a file with this setting in either state, then the XML file will not "grow". If it did, then that would be a bug. If you parse in and keep whitespace, then write out in the other mode, then you are pushing the "skip whitespace" feature past what it was designed to support. I'm not sure why these line breaks are so important to you, but line breaks and whitespace in XML files is meant to have no meaning other than aesthetics, so we provide an option so that you either do your own formatting because your whitespace has meaning or you don't like the way we do it (skip white spaces off), or you let the class do the formatting for you (skip white spaces on). http://www.w3.org/TR/2000/REC-xml-20001006#sec-white-space So you want a mode where skipWhiteSpaces won't junk whitespace intrernally in the text data of an element? It will preserve all tabs, newlines, and spaces, and junk them only if the entire textual content is whitespace, and ltrim() and rtrim() all other entries? If there is a general desire for such a feature to be implemented then I might have a go, but as I have no need for it, I can't see me looking into this with any kind of priority. If you want to "play" with this feature yourself, then the function you want to modify is: function _handleCharacterData($parser, $text) { if ($this->parsInCData >0) $text = $this->_translateAmpersand($text, $reverse=TRUE); if ($this->bDebugXmlParse) echo "Handling character data: '".htmlspecialchars($text)."'<br>"; if ($this->parseSkipWhiteCache AND !empty($text) AND !$this->parsInCData) { HERE >>> // Special case CR. CR always comes in a separate data. Trans. it to '' or ' '. HERE >>> // If txtBuffer is already ending with a space use '' otherwise ' '. $bufferHasEndingSpace = (empty($this->parsedTextLocation) OR substr($this->parsedTextLocation, -1) === ' ') ? TRUE : FALSE; if ($text=="\n") { $text = $bufferHasEndingSpace ? '' : ' '; } else { if ($bufferHasEndingSpace) { $text = ltrim(preg_replace('/\s+/', ' ', $text)); } else { $text = preg_replace('/\s+/', ' ', $text); } } if ($this->bDebugXmlParse) echo "'Skip white space' is ON. reduced to : '" .htmlspecialchars($text) . "'<br>"; } $this->parsedTextLocation .= $text; } If you come up with something that works quite well then if you send the change in then we'll look into incorporating it into the main branch. Cheers, Nigel > ----- Original Message ----- > From: "Nigel Swinson" <nig...@us...> > To: "Jens Habermann" <Jen...@we...> > Cc: <php...@li...> > Sent: Tuesday, July 23, 2002 12:23 PM > Subject: Re: Files unformatted > > > > Ok I ran your script and see the same output, so I'm glad to say that this > > isn't a freak issue that won't "travel". :o) > > > > Using the SkipWhitespaces option, and the string you are inputing I can > get: > > > > import without export without > > > > <?xml version="1.0"?> > > <aaa><bbb>This is > > a text > > with linebreaks!</bbb></aaa> > > > > import with export without (Your example was missing this one...) > > > > <?xml version="1.0"?> > > <aaa><bbb>This is a text with linebreaks!</bbb></aaa> > > > > import with export with (This is the one you labelled "buggy") > > > > <?xml version="1.0"?> > > <aaa> > > <bbb>This is a text with linebreaks!</bbb> > > </aaa> > > > > import without export with > > > > <?xml version="1.0"?> > > <aaa> > > <bbb>This is > > a text > > with linebreaks!</bbb> > > </aaa> > > > > Which seems to be all four possible options. Will none of these do you? > If > > not then what do you want? :o/ > > > > 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: "Jens Habermann" <Jen...@we...> > > To: "Nigel Swinson" <nig...@us...> > > Sent: Monday, July 22, 2002 11:59 PM > > Subject: Re: Files unformatted > > > > > > > OK here it is :) > > > > > > Ive written a little example which outputs 3 different xml files. Inside > > the > > > example.php i described the problem. > > > > > > The output files as i get them are included too. Take a look at them > > before > > > starting the example.php to realise the difference between them. I think > > you > > > will get the same output as iam but maybe you wont believe me but your > > eyes > > > :) > > > > > > ----- Original Message ----- > > > From: "Nigel Swinson" <nig...@us...> > > > To: "Jens Habermann" <Jen...@we...> > > > Sent: Tuesday, July 23, 2002 12:13 AM > > > Subject: Re: Files unformatted > > > > > > > > > > > Ok here is an example: > > > > > > > > > > <aaa>This is > > > > > > > > > > a text > > > > > > > > > > that has line breaks > > > > > </aaa> > > > > > > > > > > if i toggle whitespace to TRUE the output is: <aaa>This is a text > that > > > has > > > > > line breaks</aaa> > > > > > > > > > > What ive found out so far is that the trim function of php also > > deletes > > > > > linebreaks ("\n") what seems to be the problem... > > > > > > > > > > So i have to choose if i want to have pretty printed text without > > > > linebreaks > > > > > or an unreadable chunk with linebreaks :) > > > > > > > > > > I have included another variable to the PHP.XPath class called > > > > > $prettyPrinted. At the moment im looking for all the places where > the > > > > class > > > > > formats the text and write some new lines which are checking for a > > true > > > > > $prettyPrinted variable and then do the same as skipWhitespace des > > > without > > > > > deleting my linebreaks :) > > > > > > > > Well good luck then :o) > > > > > > > > If you want me to help you, then I have to be able to reproduce the > > issue > > > > locally, which means me running EXACTLY the same .php and .xml input > and > > > > then comparing the generated output (html? xml?). I need more than > > just > > > an > > > > example of xml with a paragraph describing the operation. I need to > be > > > able > > > > to copy a couple of attachments to a folder, point my browser at the > php > > > > page, and then examine the results. :o) > > > > > > > > Sounds like you are happy sorting it out on your own :o). My only > > concern > > > > (for you) is that your changes aren't going to make it into the main > > > branch, > > > > which means you are gonna have to keep re-applying them.... > > > > > > > > Nigel > > > > > > > > > > |
From: Peter R. <php...@pe...> - 2002-07-23 09:11:57
|
On Monday 22 Jul 2002 20:50, Nigel Swinson wrote: > > Let me know if this doesn't fix the problem properly... yup, problem seems to be fixed, thanks |
From: Nigel S. <nig...@us...> - 2002-07-22 21:36:45
|
> Now i tested the skipWhitespace option. The default option is FALSE to make > the parser work faster i think. If i set it TRUE the files are pretty > printed BUT the problem i get is that line breaks are no longer recognized > by the parser... "line breaks are no longer recongnized by the parser" ? I don't understand... > I dont know what white space skip has together with pretty printig If you "skip white spaces" then on input, whitespace is junked, and on output it is pretty printed. If skip white spaces is off, then an import/export should produce basically an identical file. > but i > think there should be another option to toggle what independent from white > space skip toggles pretty printing. I don't understand what it is that you are asking for :o( > By the way: PHP.XPath v2.2 does it that > way. It was pretty printing the text even with white space skip... Any change between 2.2 and 3.0 in this area is unintentional. I thought that in 2.2 an import/export without skipping whitespace would produce identical output to the input. A concise example of the input you are using to see this behaviour, and the output it generates would help to make this discussion concrete. Cheers, Nigel |
From: Nigel S. <nig...@us...> - 2002-07-22 19:58:28
|
That's odd, this doesn't happen for me. If I use the use cases test harness, it calls: $xPath->exportToFile($xmlDirectory.$HTTP_POST_VARS['XmlFile'].'.new.xml'); And the gui gives you a setting to toggle the "skip whitespace option". If I don't use "skip whitespace" then the output is as it was for the input. If I use skip whitespace, then the output is "pretty printed". In neither scenario that I can see does it junk the whitespace :o/ So no by no means was this the intended behaviour. Could you package up a php file that demonstrates the problem as concisely as possible and we can see if this is a bug on all systems, or just yours, and if there is some way we can code round to make it work? Much appreciated, Thanks, 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: Jens Habermann To: php...@li... Sent: Monday, July 22, 2002 12:56 PM Subject: Files unformatted I downloaded the new version (v3.2) of the class an half hour ago and now i had to realise that the file output is no longer formatted. Example: (old php.xpath output to file) <aaa> <bbb/> <ccc>text</ccc> </aaa> (new php.xpath output to file) <aaa><bbb/><ccc>text</ccc></aaa> I cannot believe that this was intended... |
From: Nigel S. <nig...@us...> - 2002-07-22 19:53:29
|
> > I've tagged this one as "stable" because it's > > been a while since there were any bug reports, but if you spot any, > > then let us know and we'll do another release. > > the sum function no longer seems to work - seems to always return 0. > Given: > > <km>100</km> > <km>200</km> > > evaluate("sum(//km)") > should surely return 300. > > This was working in 3.0. And the prize for finding the first 3.2 bugs goes to.... Peter :o) My humblest apologies, I never use the sum() function, and there was no entry in the test harness, so I only gave it a cursory glance during the coding for 3.2. I thought sum() took a single integer argument, when in fact it is meant to take a node set. :o( This has been fixed now, and a test added to the test harness so that future releases will never suffer from this bug :o) The changes are fairly slight, just change the function to this: function _handleFunction_sum($arguments, $context) { $arguments = trim($arguments); // Trim the arguments. // Evaluate the arguments as an XPath query. $result = $this->_evaluateExpr($arguments, $context); $sum = 0; // Create a variable to save the sum. // The sum function expects a node set as an argument. if (is_array($result)) { // Run through all results. $size = sizeOf($result); for ($i=0; $i<$size; $i++) { $value = $this->_handleFunction_number($result[$i], $context); $sum += doubleval($value); // Add it to the sum. } } return $sum; // Return the sum. } Let me know if this doesn't fix the problem properly... Nigel |
From: Philipp L. <le...@hi...> - 2002-07-22 19:39:08
|
From: "Nigel Swinson" <nig...@us...> >... > This change went in recently (Before 3.2) >... > $self = isSet($_SERVER) ? $_SERVER['PHP_SELF'] : $PHP_SELF; > > Is this enough for you? If not feel free to send us your change and we'll > see if we can put it in the main branch... > Ah, that's already solved then! Thanks! |
From: Nigel S. <nig...@us...> - 2002-07-22 19:31:35
|
> Sorry, forgot if I mentioned -- I installed the newest PHP on my Win 98/ > PWS recently, and had to change a line in the XPath-class because it > didn't work anymore (I changed the single "self" reference somewhere). This change went in recently (Before 3.2) ---------------------------- Revision : 1.107 Date : 2002/7/20 11:32:45 Author : 'bs_php' State : 'Exp' Lines : +3 -2 Description : PHP V4.1.x handles predefined globles differently. Had to catch that : $self = isSet($_SERVER) ? $_SERVER['PHP_SELF'] : $PHP_SELF; Is this enough for you? If not feel free to send us your change and we'll see if we can put it in the main branch... :o) Nigel =========================== For the most recent version of Php.XPath, and an archive of this list visit: http://www.sourceforge.net/projects/phpxpath |
From: Nigel S. <nig...@us...> - 2002-07-22 19:28:20
|
> I was using a very old version of phpxpath and have been reluctant to > upgrade because it has been working so well for me. SInce I lurk here I > knew the later versions were faster so I finally downloaded the latest > version and decided to test it. It turns out that phpxpath is now a whole > new animal and the API has changed quite a bit. Here is a snippet of how I > was using this class. We actually supported both old and new methods all the way through the 2.X branch, but expired the "old" methods as of 3.0. We changed the function names to be more like the DOM api, as we felt this would reduce the learning curve to our users. > $xml = new XPath(); > $xml->load_string ($results_xml); http://www.carrubbers.org/scripts/php/xpath/doc/#importFromString > $a = $xml->get_attributes($xml->root); http://www.carrubbers.org/scripts/php/xpath/doc/#getAttributes > $resultcount = $a['COUNT']; > > if ($resultcount): > // we know we have results so let's deal with them. > $results = $xml->evaluate("/RESULTS/RESULT"); This is still in as: http://www.carrubbers.org/scripts/php/xpath/doc/#evaluate In general it was just function name changes, but there were some differences along the way, please backup data and test well before releasing on your production site (As we should always do, and I didn't) :o) Cheers, Nigel |
From: Philipp L. <le...@hi...> - 2002-07-22 18:36:40
|
Sorry, forgot if I mentioned -- I installed the newest PHP on my Win 98/ PWS recently, and had to change a line in the XPath-class because it didn't work anymore (I changed the single "self" reference somewhere). |
From: <im...@ca...> - 2002-07-22 17:31:33
|
From: Tim U. <ti...@di...> - 2002-07-22 15:50:06
|
Hello all. I was using a very old version of phpxpath and have been reluctant to upgrade because it has been working so well for me. SInce I lurk here I knew the later versions were faster so I finally downloaded the latest version and decided to test it. It turns out that phpxpath is now a whole new animal and the API has changed quite a bit. Here is a snippet of how I was using this class. $xml = new XPath(); $xml->load_string ($results_xml); $a = $xml->get_attributes($xml->root); $resultcount = $a['COUNT']; if ($resultcount): // we know we have results so let's deal with them. $results = $xml->evaluate("/RESULTS/RESULT"); foreach ($results as $result): // everything we need is in here. $atrributes = $xml->get_attributes($result); $cases = $xml->evaluate($result . '/CASES/CASE'); foreach ($cases as $case): $case = $xml->get_attributes($case); foreach ($case as $key => $value): Do something here with the case attributes. endforeach; endforeach; endforeach; else: $error .= "No results found"; endif; To me this was a very neat way of dealing with XML files. Has this all now gone away? What is the eqavalent code in the new API. :wq Tim Uckun US Investigations Services/Due Diligence http://www.diligence.com/ |