[jdom-interest] handling xml:space attribute

Jason Hunter jhunter at collab.net
Wed Jun 21 16:14:24 PDT 2000


I just changed Verifier to allow xml:space and xml:language as attribute
names.  Gabor, the code's in CVS.  Please check things out to make sure
it's working for you.  If anyone has problems with this special case,
speak now.

-jh-

Gabor Greif wrote:
> 
> 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?



More information about the jdom-interest mailing list