|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-05-27 13:45 UTC] danielklein at airpost dot net
Description: ------------ A simple XPath that matches namespaces should return all nodes, however, it only returns every second one. Using the below link I confirmed this issue for all versions of PHP 5.0.0 - 5.6.9 http://3v4l.org/4qZhu Test script: --------------- <?php $doc = new DOMDocument('1.0', 'UTF-8'); $doc->loadXML('<root xmlns:ns="foo" ns:id="1"> <one/> <two/> <three/> <four/> <five/> </root>'); $finder = new DOMXPath($doc); $nodes = $finder->query("//node()[namespace::ns]"); foreach ($nodes as $n) { var_dump($doc->saveXML($n)); } Expected result: ---------------- string(78) "<root xmlns:ns="foo" ns:id="1"> <one/> <two/> <three/> <four/> <five/> </root>" string(6) "<one/>" string(6) "<two/>" string(8) "<three/>" string(7) "<four/>" string(7) "<five/>" Actual result: -------------- string(78) "<root xmlns:ns="foo" ns:id="1"> <one/> <two/> <three/> <four/> <five/> </root>" string(6) "<two/>" string(7) "<four/>" PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 04:00:01 2025 UTC |
Unfortunately this looks like a bug with libxml and not with PHP: Python import libxml2 doc = libxml2.parseFile("69712.xml") ctxt = doc.xpathNewContext() res = ctxt.xpathEval("//node()[namespace::ns]") print "Found %d nodes\n" % len(res) finds 3 nodes as well. Take a look through their tracker[1] to see if there's a bug report for it already (I didn't see one) and if not please make one. This may also be a symptom of libxml's general problem with namespaces (eg, [2]). [1] https://bugzilla.gnome.org/buglist.cgi?product=libxml2 [2] https://bugzilla.gnome.org/show_bug.cgi?id=705413