Skip to content

Commit

Permalink
Avoid potential double namespace prefix; #31
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Nov 17, 2022
1 parent 528e730 commit d1610d2
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions ph-xml/src/main/java/com/helger/xml/XMLHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,18 @@ private static String _getPathToNode (@Nonnull final Node aNode,
break;
}

final StringBuilder aName = new StringBuilder (aCurNode.getNodeName ());
final String sNamespaceURI = aCurNode.getNamespaceURI ();

final StringBuilder aName = new StringBuilder ();
if (nNodeType == Node.ATTRIBUTE_NODE)
aName.append ('@');
if (StringHelper.hasText (sNamespaceURI))
{
aName.append (funGetNSPrefix.apply (sNamespaceURI));
aName.append (aCurNode.getLocalName ());
}
else
aName.append (aCurNode.getNodeName ());

final Node aParentNode;
if (nNodeType == Node.ATTRIBUTE_NODE)
Expand Down Expand Up @@ -633,11 +644,7 @@ private static String _getPathToNode (@Nonnull final Node aNode,
// Avoid trailing separator
aRet.insert (0, sSep);
}

aRet.insert (0, aName);
aRet.insert (0, funGetNSPrefix.apply (aCurNode.getNamespaceURI ()));
if (nNodeType == Node.ATTRIBUTE_NODE)
aRet.insert (0, '@');

// goto parent
aCurNode = aParentNode;
Expand Down

0 comments on commit d1610d2

Please sign in to comment.