Re: [PHP] PHP5, XPath and count()
On Sat, 24 Jul 2004 17:35:59 +0200, Victor Boivie <[EMAIL PROTECTED]> wrote: > Christian Stocker wrote: > > >>var_dump($xpath->query("count(/catalog/cd")->item(0)); > > > > > > this doesn't work yet in DOM. The returned value has to be a nodeset. > > Will be fixed some day ;) > > > > Thanks, both Jason and Christian > > I found something else that I think is strange. > >$dom = new DOMDocument(); > >$root = $dom->createElement("test"); >$dom->appendChild($root); > >$node = $dom->createElement("foo", "which entities does it > escape & which doesn't it?"); >$root->appendChild($node); > >echo $dom->saveXML(); Yep, that looks like a bug... Can you please file a bug at bugs.php.net? The workaround is the write the following: $node = $dom->createElement("foo"); $text = $dom->createTextNode( "which entities does it escape & which doesn't it?"); $node->appendChild($text); $root->appendChild($node); While a little more to type, it's at least the official W3C way ;) chregu > > The result will be: > > > which entities does it escape > > It stops at the &, which I think is strange. It escapes the < to < > and > to >, but not & to &. It would be better if it escaped none > or all entites that "can do harm". > > Or what do you think? > regards, > Victor > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- christian stocker | Bitflux GmbH | schoeneggstrasse 5 | ch-8004 zurich phone +41 1 240 56 70 | mobile +41 76 561 88 60 | fax +41 1 240 56 71 http://www.bitflux.ch | [EMAIL PROTECTED] | gnupg-keyid 0x5CE1DECB -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP5, XPath and count()
Christian Stocker wrote: var_dump($xpath->query("count(/catalog/cd")->item(0)); this doesn't work yet in DOM. The returned value has to be a nodeset. Will be fixed some day ;) Thanks, both Jason and Christian I found something else that I think is strange. $dom = new DOMDocument(); $root = $dom->createElement("test"); $dom->appendChild($root); $node = $dom->createElement("foo", "which entities does it escape & which doesn't it?"); $root->appendChild($node); echo $dom->saveXML(); The result will be: which entities does it escape It stops at the &, which I think is strange. It escapes the < to < and > to >, but not & to &. It would be better if it escaped none or all entites that "can do harm". Or what do you think? regards, Victor -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP5, XPath and count()
this doesn't work yet in DOM. The returned value has to be a nodeset. Will be fixed some day ;) see victors answer for the work around chregu I was wondering about that. So is there someplace online where we can find out what does / does not yet work for XPath? I've been looking but google only gives about 9 hits for DomXPath. If I wasn't such a lousy C coder I'd try to go trudging through the source myself :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP5, XPath and count()
On Tue, 20 Jul 2004 22:57:20 +0200, Victor Boivie <[EMAIL PROTECTED]> wrote: > Assume an XML file that looks like: > > > >.. > > >.. > > .. > > > ... and that I would like to know the number of CDs. An xpath expression > would look like count(/catalog/cd), but how do I run this expression? > > $dom = new DOMDocument(); > $dom->load("catalog.xml"); > $xpath = new DOMXpath($dom); > var_dump($xpath->query("count(/catalog/cd")->item(0)); this doesn't work yet in DOM. The returned value has to be a nodeset. Will be fixed some day ;) see victors answer for the work around chregu > > ... returns NULL. > > Any ideas? > > Thanks in advance, > Victor > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- christian stocker | Bitflux GmbH | schoeneggstrasse 5 | ch-8004 zurich phone +41 1 240 56 70 | mobile +41 76 561 88 60 | fax +41 1 240 56 71 http://www.bitflux.ch | [EMAIL PROTECTED] | gnupg-keyid 0x5CE1DECB -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP5, XPath and count()
Assume an XML file that looks like: .. .. .. ... and that I would like to know the number of CDs. An xpath expression would look like count(/catalog/cd), but how do I run this expression? $dom = new DOMDocument(); $dom->load("catalog.xml"); $xpath = new DOMXpath($dom); var_dump($xpath->query("count(/catalog/cd")->item(0)); ... returns NULL. Any ideas? Thanks in advance, Victor -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php