Skip to content

Commit baa4f0d

Browse files
committed
PDFBOX-6027: second setAttributeNS() parameter must be "xml:lang" instead of "lang" to avoid troubles if Apache Xalan is in the classpath
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1926774 13f79535-47bb-0310-9956-ffa450edef68
1 parent 67c8944 commit baa4f0d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

xmpbox/src/main/java/org/apache/xmpbox/xml/XmpSerializer.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,22 @@ public void serializeFields(Document doc, Element parent, List<AbstractField> fi
140140
List<Attribute> attributes = simple.getAllAttributes();
141141
for (Attribute attribute : attributes)
142142
{
143-
esimple.setAttributeNS(attribute.getNamespace(), attribute.getName(), attribute.getValue());
143+
String name = attribute.getName();
144+
// we must add "xml:" to the qualifiedName parameter or it won't appear in the result
145+
// If a more strict transformer like Apache Xalan is in the classpath (e.g. PDFBOX-4817)
146+
if (XMLConstants.XML_NS_URI.equals(attribute.getNamespace()) &&
147+
name != null && !name.contains(":"))
148+
{
149+
esimple.setAttributeNS(XMLConstants.XML_NS_URI,
150+
XMLConstants.XML_NS_PREFIX + ":" + name,
151+
attribute.getValue());
152+
}
153+
else
154+
{
155+
esimple.setAttributeNS(attribute.getNamespace(),
156+
name,
157+
attribute.getValue());
158+
}
144159
}
145160
parent.appendChild(esimple);
146161
}

0 commit comments

Comments
 (0)