Details
-
Bug
-
Status: Open
-
Critical
-
Resolution: Unresolved
-
2.7
-
None
-
None
-
PatchAvailable
Description
Here is a simple test case to reproduce the problem:
code
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
TransformerFactory tf = TransformerFactory.newInstance();
String src = "<root><xmlConfiguration:xmlConfiguration xmlns:xmlConfiguration=\"urn:configuration\" /></root>";
Document doc = dbf.newDocumentBuilder().parse(new ByteArrayInputStream(src.getBytes()));
ByteArrayOutputStream res = new ByteArrayOutputStream();
tf.newTransformer().transform(new DOMSource(doc), new StreamResult(res));
System.out.println(res);
dbf.newDocumentBuilder().parse(new ByteArrayInputStream(res.toByteArray()));
code
The last line throws an exception, because the xmlns:xmlConfiguration attribute has been lost.
While debugging, I found that the problem comes from http://svn.apache.org/repos/asf/xalan/java/trunk/src/org/apache/xml/serializer/NamespaceMappings.java,
line 228:
code
// Prefixes "xml" and "xmlns" cannot be redefined
if (prefix.startsWith(XML_PREFIX))
code
It seems this test is wrong, and it should be
code
// Prefixes "xml" and "xmlns" cannot be redefined
if (prefix.equals("xml") || prefix.equals("xmlns")
{ return false; }
code