Doc #49490 [ReO->Csd]: XPath namespace prefix conflict
| From: | kalle@php.net | Date: | Sat, 23 Oct 2010 05:31:16 +0000 |
| Subject: | Doc #49490 [ReO->Csd]: XPath namespace prefix conflict | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-5341@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=49490&edit=1
ID: 49490
Updated by: kalle@php.net
Reported by: olav dot morken at uninett dot no
Summary: XPath namespace prefix conflict
-Status: Re-Opened
+Status: Closed
Type: Documentation Problem
Package: Documentation problem
Operating System: Linux (Debian)
PHP Version: 5.3.0
-Assigned To:
+Assigned To: kalle
Block user comment: N
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
Previous Comments:
------------------------------------------------------------------------
[2010-10-23 07:30:57] kalle@php.net
Automatic comment from SVN on behalf of kalle
Revision: http://svn.php.net/viewvc/?view=revision&revision=304636
Log: Fixed bug #49490 (XPath namespace prefix conflict)
------------------------------------------------------------------------
[2010-05-07 23:10:33] bjori@php.net
Re-open as documentation issue:
New argument added.
------------------------------------------------------------------------
[2010-05-04 17:47:11] rrichards@php.net
This bug has been fixed in SVN.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Automatic namespace registration really wasn't a good idea from the get
go.
Performance starts taking a hit the deeper in the tree a context node.
The patch
in the bug report was not used; rather a new third argument has been
added to
the query() and evalute() methods, which allows automatic registration
of the
context node to be disabled. For BC reasons auto registration is enabled
by
default. When auto registration is disabled and context nodes are used
XPath
performance will be increased.
i.e.
echo($xp->query('//prefix:root', null, false)->length . "\n");
------------------------------------------------------------------------
[2010-05-04 17:41:51] rrichards@php.net
Automatic comment from SVN on behalf of rrichards
Revision: http://svn.php.net/viewvc/?view=revision&revision=298974
Log: fix bug #49490 (XPath namespace prefix conflict)
add test
------------------------------------------------------------------------
[2010-04-17 11:14:50] thomas at weinert dot info
It looks like DOMXPath->evaluate()/DOMXPath->query() registers the
namespace prefixes of the given context and overrides any definition
from DOMXPath->registerNamespace(). PHP should not register any
namespaces from the context or at least prefer manual registrations over
automatic.
Reproduce code:
---------------
$dom = new DOMDocument();
$dom->loadXML(
'<foobar><a:foo xmlns:a="urn:a">'.
'<b:bar xmlns:b="urn:b"/></a:foo>'.
'</foobar>'
);
$xpath = new DOMXPath($dom);
//get context node and check "a:foo"
$context = $dom->documentElement->firstChild;
var_dump($context->tagName);
// try to override the context node
$xpath->registerNamespace('a', 'urn:b');
var_dump(
$xpath->evaluate(
'descendant-or-self::a:*',
$context
)->item(0)->tagName
);
// use a prefix not used in context
$xpath->registerNamespace('prefix', 'urn:b');
var_dump(
$xpath->evaluate(
'descendant-or-self::prefix:*',
$context
)->item(0)->tagName
);
Expected result:
----------------
string(5) "a:foo"
string(5) "b:bar"
string(5) "b:bar"
Actual result:
----------------
string(5) "a:foo"
string(5) "a:foo"
string(5) "b:bar"
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/bug.php?id=49490
--
Edit this bug report at http://bugs.php.net/bug.php?id=49490&edit=1