Bug #69712 [Opn->Nab]: XPath selecting namespaced nodes only matches every second one

From: Date: Wed, 27 May 2015 20:50:18 +0000
Subject: Bug #69712 [Opn->Nab]: XPath selecting namespaced nodes only matches every second one
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192935@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69712&edit=1 ID: 69712 Updated by: requinix@php.net Reported by: danielklein at airpost dot net Summary: XPath selecting namespaced nodes only matches every second one -Status: Open +Status: Not a bug Type: Bug Package: DOM XML related Operating System: * PHP Version: 5.6.9 Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2015-05-27 13:45:55] 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/>" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69712&edit=1

« previous php.bugs (#192935) next »