|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
[Issue 10] New - DOMDocumentSerializer : namespace problemhttps://fi.dev.java.net/issues/show_bug.cgi?id=10
Issue #|10 Summary|DOMDocumentSerializer : namespace problem Component|fi Version|current Platform|PC OS/Version|Windows XP URL| Status|NEW Status whiteboard| Keywords| Resolution| Issue type|DEFECT Priority|P1 Subcomponent|www Assigned to|sandoz Reported by|dmucha ------- Additional comments from dmucha@... Mon Nov 27 14:24:52 +0000 2006 ------- I have a namespace problem with DOMDocumentSerializer : IOException: namespace URI of local name not indexed (found on Windows XP, probably an all platform all OS issue) I thought the DOM Level 2 compliant way to create the following document is /* * <?xml version="1.0" encoding="UTF-8"?> * <root xmlns="http://NewDefaultNamespaceURI.xxx.org"> * <ABC:e xmlns:ABC="http://www.xxx.org"/> * </root> */ Document doc = db.newDocument(); Element root = doc.createElementNS("http://NewDefaultNamespaceURI.xxx.org", "root"); doc.appendChild(root); Element e = doc.createElementNS("http://www.xxx.org", "ABC:e"); root.appendChild(e); I can serialize this with com.sun.org.apache.xml.internal.serialize.XMLSerializer and convert it to a string and everything is ok. When I serialize it with com.sun.xml.fastinfoset.dom.DOMDocumentSerializer into a fastinfoset document I get an IOException (complete unit test see below) : java.io.IOException: namespace URI of local name not indexed: http://NewDefaultNamespaceURI.xxx.org at com.sun.xml.fastinfoset.Encoder.encodeLiteralElementQualifiedNameOnThirdBit(Encoder.java:826) So DOMDocumentSerializer shows a different behaviour than XMLSerializer with the same document. When I add the namespace additionally as an attribute via setAttributeNS the call to com.sun.xml.fastinfoset.dom.DOMDocumentSerializer.serialize succeeds : Document doc = db.newDocument(); Element root = doc.createElementNS("http://NewDefaultNamespaceURI.xxx.org", "root"); root.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", "http://NewDefaultNamespaceURI.xxx.org"); doc.appendChild(root); Element e = doc.createElementNS("http://www.xxx.org", "ABC:e"); e.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:ABC", "http://www.xxx.org"); root.appendChild(e); It seems to me that DOMDocumentSerializer needs the namespace as an attribute to do its task with DOM Level 2 elements. The parser generates the additional attributes for the namespaces, so the serializer works in a round trip environment. Only if a program generated document is serialized the above problems occur. In the forum I found a message addressing attributes and namespaces http://forums.java.net/jive/thread.jspa?forumID=44&threadID=2585&messageID=36634#36634 > Paul Sandoz wrote : > The DOM serializer is currently a bit dumb and does not declare namespaces. > It is necessary for the namespace declarations to already be declared. Dietrich public void testDoNotIgnoreDOMSerializationNamespaceProblem() throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); /* create the following document : <?xml version="1.0" encoding="UTF-8"?> <root xmlns="http://NewDefaultNamespaceURI.xxx.org"> <ABC:e xmlns:ABC="http://www.xxx.org"/> </root> */ Document doc = db.newDocument(); Element root = doc.createElementNS("http://NewDefaultNamespaceURI.xxx.org", "root"); // --> setAttributeNS is needed for ds.serialize(doc) to succeed root.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", "http://NewDefaultNamespaceURI.xxx.org"); doc.appendChild(root); Element e = doc.createElementNS("http://www.xxx.org", "ABC:e"); // --> setAttributeNS is needed for ds.serialize(doc) to succeed e.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:ABC", "http://www.xxx.org"); root.appendChild(e); DOMDocumentSerializer ds = new DOMDocumentSerializer(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ds.setOutputStream(baos); ds.setIgnoreComments(false); ds.setIgnoreProcesingInstructions(false); ds.setIgnoreWhiteSpaceTextContent(false); ds.serialize(doc); Document docOut = db.newDocument(); DOMDocumentParser parser = new DOMDocumentParser(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); parser.parse(docOut, bais); } --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscribe@... For additional commands, e-mail: issues-help@... |
| Free Forum Powered by Nabble | Forum Help |