Resetting the default namespace causes a serious endless loop when requesting
.asPath() on a node.
--------------------------------------------------------------------------------------------------
Key: JXPATH-154
URL: https://issues.apache.org/jira/browse/JXPATH-154
Project: Commons JXPath
Issue Type: Bug
Affects Versions: 1.3
Environment: jxpath eclipse plugin from orbit
Reporter: Hugo de Almeida Cocharro
sample smaller case:
{code}
<...>
<b:foo xmlns:b="bla" xmlns="test111"> <!-- No nodes are placed in the tree
within ns "test111" but the attribute is still there.-->
<b:bar>a</b:bar> <!-- is in ns 'bla' -->
<test xmlns=""></test> <!-- does not have a namespace -->
</b:foo>
</...>
{code}
when requesting .asPath() on the 'test' node, it loops in
org.apache.commons.jxpath.ri.NamespaceResolver.getPrefix(NodePointer, String),
and if it didn't loop it would create a wrong xpath '//'
DOMNodePointer.asPath().
So I think that the fix should be in
org.apache.commons.jxpath.ri.model.dom.DOMNodePointer.asPath()
{code}
....
String ln = DOMNodePointer.getLocalName(node);
String nsURI = getNamespaceURI();
if (nsURI == null) {
buffer.append(ln);
buffer.append('[');
buffer.append(getRelativePositionByName()).append(']');
}
else {
String prefix = getNamespaceResolver().getPrefix(nsURI);
if (prefix != null) {
...
{code}
should become
{code}
...
String ln = DOMNodePointer.getLocalName(node);
String nsURI = getNamespaceURI();
if (nsURI == null || nsURI.length() == 0) { // check for
empty string which means that the node doesn't have a namespace.
buffer.append(ln);
buffer.append('[');
buffer.append(getRelativePositionByName()).append(']');
}
else {
String prefix = getNamespaceResolver().getPrefix(nsURI);
if (prefix != null) {
...
{code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira