public
class DomDocumentBug { public static void main(String[] args) throws Exception {
SAXReader reader = new SAXReader(new
DOMDocumentFactory());
Document d = reader.read(new StringReader("<doc xml:version=\"1\"/>"));
System.out.println(d.asXML());
SAXReader s2 = new
SAXReader();
Document d2 = s2.read(new StringReader(d.asXML()));
System.out.println(d2.asXML());
}
}
---
protected boolean
isNamespaceDeclaration(Namespace ns) {
if ((ns !=
null) && (ns !=
Namespace.XML_NAMESPACE))
{
String uri = ns.getURI();
if (uri != null)
{
if (!namespaceStack.contains(ns)) {
return true;
}
}
}
return false;
}
----
the comparison is equality on XML_NAMESPACE should be .equals, not == as other namespace nodes can be created and present in the structures, whether generated automatically,as in this example, or programatically, so the comparisong could be
if ((ns != null) && (!ns.equals(Namespace.XML_NAMESPACE))) {
This will cause the element field of the DefaultNamespace to be taken into account, which is not relevent, so this could be converted to check the prefix and the uri, but this is what the namespace stack does isnt it?
Would the better solution be to push the XML_NAMESPACE into the namespace stack when the NO_NAMESPACE is pushed, in the constructors for the NamespaceStack, as half of the exclusion logic is in the XMLWriter and half in the NamespaceStack, and the encapsulation is IMHO compromised
The DomDocumentFactory subclasses the standard namespace, as to comply with the w3c Node interface, is has additional methods. At any rate the user may create a namespace directly, rather that going through the cache, so the same situation may occur in other types of trees
Are there any more implicit namespaces that need special handling, and omission from the serialised form?
Mike
------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________ dom4j-dev mailing list dom4j-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/dom4j-dev