[jdom-interest] handling xml:space attribute

Gabor Greif gabor at no.netopia.com
Mon Jun 19 05:08:31 PDT 2000


I have a problem with xml:space and xml:language.

These are standard attributes if I read the spec correctly.
However JDOM b4 only lets me add this to an element as an attribute if I
also specify the namespace for the attribute.

Now I do something like this:

elem.addAttribute(new Attribute("space", "preserve",
Namespace.getNamespace("xml", "myURI")));

the prettyprinted tag looks like this:

  <ostype name="id" xmlns:xml="myURI" xml:space="preserve">0</ostype>

I want to get rid of the xmlns:xml="myURI" attribute.

For this I tried to introduce the namespace in the root element by adding
(before the above):

doc.getRootElement().addAttribute(new Attribute("xmlns", "myURN",
Namespace.getNamespace("xml", "myURI")));

This led to (relevant part shown):

<pane xmlns:xml="myURI" xml:xmlns="myURN">
  <ostype name="id" xmlns:xml="myURI" xml:space="preserve">0</ostype>
</pane>

Now the <ostype> tag still contains xmlns:xml="myURI"

:-(

Of course attribute name validation wont let me add 
elem.addAttribute("xml:space", "preserve");

as it would be natural for these special attributes.

I have the impression that xml:space and xml:language should be
special-cased in Verifier.checkAttributeName and accepted as a regular name
without namespace magic...

I am stumped. Can somebody tell how I can suppress the xmlns:xml="myURI" in
tags not on toplevel?


Thanks in advance,

	Gabor






More information about the jdom-interest mailing list