[jdom-interest] Beta 9 RC1 (tiny namespace bug)

Mike Brenner mikeb at mitre.org
Fri Apr 11 12:54:57 PDT 2003


Jason Hunter wrote:
> I just built and posted "JDOM 1.0 Beta 9 Release Candidate #1".
> Get it here: http://www.jdom.org/dist/binary


Hi Jason,

There may be a tiny bug, as described here.

When creating JDOM documents, one element at a time
in memory, we sometimes desire to have the following effect:

	<mytag> </mytag>

instead of the abbreviation:

	<mytag/>

That is, I desire an open and close tag with no text in between.

This is required, so that Javascript can add children to that node later,
in SVG graphics documents that are modified dynamically on the web.

One cannot achieve this effect by putting text composed of blanks,
non-breaking spaces (in either hex or html format), etc.

But one can achieve it, in JDOM b8, with the following command:

	Element text = new Element("text");
	text.setAttribute("xml:space", "preserve");

JDOM b8 did not require a namespace to be set for this to work.
In JDOM b9 the workaround is to use the following 

	Namespace xml = Namespace.getNamespace("xml", 
		"http://www.w3.org/XML/1998/namespace");	
	Element text = new Element("text");
	text.setAttribute("space", "preserve", xml);

THIS IS A BUG, BECAUSE the xml namespace is always 
supposed to be available in all xml tools.

But in JDOM b9, the following error message occurs, if the above b8 code is used under b9:

org.jdom.IllegalNameException: 
The name "xml:space" is not legal for JDOM/XML attributes: 
Attribute names cannot contain colons.
 at org.jdom.Attribute.setName(Attribute.java:360)
 at org.jdom.Attribute.<init>(Attribute.java:228)
 at org.jdom.Attribute.<init>(Attribute.java:252)
 at org.jdom.Element.setAttribute(Element.java:1238
 at org.mitre.alloc.OutputSVG.createRowText(OutputSVG.java:5840)
...




More information about the jdom-interest mailing list