[jdom-interest] possible FAQ entry for NO_NAMESPACE namespace
philip.nelson at omniresources.com
philip.nelson at omniresources.com
Fri Mar 30 08:51:10 PST 2001
Why does my code output elements with xmlns="" when I have already defined a
default namespace?
JDOM explicity sets the namespace of each element and attribute as required
by the XML specs for XML processors whether you specify one or not. The
default namespace for a JDOM element is prefix="" and uri="" (defined as
Namespace.NO_NAMESPACE). As a result, when you are using namespaces, you
construct elements like:
Namespace foo = Namespace.getNamespace("", urn:foo");
new Element("element", foo)
.addContent(new Element("child", foo));
which produces
<element xmlns="urn:foo">
<child />
</element>
If you don't specify the child namespace, or want to set an empty namespace,
you construct like:
Namespace foo = Namespace.getNamespace("", urn:foo");
new Element("element", foo))
.addContent(new Element("child"));
which produces
<element xmlns="urn:foo">
<child xmlns="" />
</element>
More information about the jdom-interest
mailing list