[jdom-interest] XmlOutputter - printNamespace - NO_NAMESPACE
outputs xmlns="", bug?
Eric VERGNAUD
eric.vergnaud at wanadoo.fr
Wed Jul 2 14:42:59 PDT 2003
le 2/07/03 23:31, John Jefferson à surfer97301 at yahoo.com a écrit :
>
> Hi,
>
> My problem is that when outputing xml some of the
> children of my document are given blank namespaces.
>
> For instance <root> <child1 xmlns=""></child1></root>
>
> The reason for this is in the method below and occurs
> because the namespace is NO_NAMESPACE but
> namespaces.getURI("") is not null.
>
> This is bad because I set the default namespace of the
> root element to a value - the value of
> namespaces.getURI("") - but the children are then
> defined to be using a different namespace the xmlns of
> "".
>
Since I ran into exactly the same problem a few weeks ago, here is the
answer:
- you need to set each child's namespace to your root namespace. This will
end up with:
<root xmlns="root"> <child1> data </child1> </root>
- this is because there seems to be no concept of a default namespace when
creating a document, while there is one when reading
- looks like I'm not the only one to think this is counter-intuitive, so
maybe it could be discussed on this list
Eric
More information about the jdom-interest
mailing list