[jdom-interest] Namespace help
Lxu at copyright.com
Wed Jul 24 11:46:01 PDT 2002
I'm having a problem on properly setting namespaces. I have a element tree built without any namespaces assigned to any elements. When I set the root element's namespace to something, it appears that all the 2nd level child elements now have an namespace that's an empty string, ie <level2_elem xml=""> when using XMLOutputter.outputString()
After debugging in to JDOM's source code, I found that the way the outputter works is that it checks the parent element's namespace URI and if the child have a different namespace URI it will print out the child's namespace, otherwise if they are the same then no xmlns="xyz" will be printed out. XMLOutputter.java line#1618. (Just to be exact, the check is done between the child and all its ancesters not just the immediate parent)
Now I don't know if this is a bug or FAD (feature as designed), but if the child namespace is null thus its URI is null, then this can be interpreted as the child implicitly inherits the parent's namespace (using elementFormDefault="qualified" attribute in the schema should be all it needs). But the current JDOM implementation pretty much says "null" is not the same as a specified parent namespace, thus I will print out this empty namespace URI even though xmlns="" looks really silly.
The consequence for me is that my client app receives this XML output from the server as a string. If schema validation is turned on on the client side when it parses the doc, then the XML is invalid because of this xmlns="" issue.
Can someone suggest what my options are here?
More information about the jdom-interest