Skip to content

Commit

Permalink
Do not put the xml namespace in a NamespaceMap
Browse files Browse the repository at this point in the history
  • Loading branch information
ndw committed Dec 6, 2022
1 parent 626d767 commit bffa7bd
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/main/java/com/xmlcalabash/util/S9apiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,32 +323,20 @@ private static void removeNamespacesWriter(TreeWriter tree, XdmNode node, HashSe

changed = changed || delete;

if (!delete) {
// Never put the xml namespace in the NamespaceMap
if (!delete && !"xml".equals(pfx)) {
newNS.add(new NamespaceBinding(pfx, uri));
}
}

NodeInfo inode = node.getUnderlyingNode();
AttributeMap attrs = inode.attributes();
ArrayList<AttributeInfo> attrList = new ArrayList<> ();
NodeName newName = NameOfNode.makeName(inode);
if (!preserveUsed) {
NamespaceBinding binding = newName.getNamespaceBinding();
if (excludeNS.contains(binding.getURI())) {
newName = new FingerprintedQName("", "", newName.getLocalPart());
}

// In this case, we may need to change some attributes too
for (AttributeInfo attr : attrs.asList()) {
String attrns = attr.getNodeName().getURI();
if (excludeNS.contains(attrns)) {
FingerprintedQName newAttrName = new FingerprintedQName("", "", attr.getNodeName().getLocalPart());
AttributeInfo newAttr = new AttributeInfo(newAttrName, attr.getType(), attr.getValue(), attr.getLocation(), attr.getProperties());
attrList.add(newAttr);
} else {
attrList.add(attr);
}
}
}

tree.addStartElement(newName, attrs, inode.getSchemaType(), new NamespaceMap(newNS));
Expand Down

0 comments on commit bffa7bd

Please sign in to comment.