[jdom-interest] Re: problem with JDOM / Namespaces (Brett McLaughlin)

Elliotte Rusty Harold elharo at metalab.unc.edu
Fri Aug 4 12:57:43 PDT 2000


At 12:42 PM +0100 8/4/00, Humphrey Sheil wrote:
>Some more information on the topic of colons in Elements and Attributes.  I
>was having the same problem and  am working against a CVS snapshot from
>8/3/2000 7 pm GMT.
>
>Results

This is confusing a lot of people. Is it in the FAQ yet? Also we 
should make the message part of the exception thrown a lot more 
specific. I suggest a FAQ entry something like this:

The XML 1.0 specification specifically reserves the colon character 
for use with XML Namespaces. No other use is compliant with XML 1.0. 
Therefore JDOM does not allow you to create element and attribute 
names that contain colons except when using namespaces. Furthermore, 
because of the way namespaces are implemented in JDOM, you cannot 
simply create an Element or Attribute with a fully qualified name 
like svg:title. That is you cannot do this,

   Element e = new Element("svg:title");

Instead you must split the two parts into a Namespace and a local 
name. This is the proper JDOM way to create an element in a namespace:

   Element e = new Element("title", "svg", "http://www.w3.org/2000/svg");

Th first argument is the local name. the second argument is the 
prefix. The third argument is the namespace URI.

The xml:lang and xml:space attributes are special cases that are 
allowed only because the XML 1.0 specification defined them before 
namespaces were current, and therefore a document that is not 
otherwise using namespaces may still want to include these two 
attributes.

+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
|                  The XML Bible (IDG Books, 1999)                   |
|              http://metalab.unc.edu/xml/books/bible/               |
|   http://www.amazon.com/exec/obidos/ISBN=0764532367/cafeaulaitA/   |
+----------------------------------+---------------------------------+
|  Read Cafe au Lait for Java News:  http://metalab.unc.edu/javafaq/ |
|  Read Cafe con Leche for XML News: http://metalab.unc.edu/xml/     |
+----------------------------------+---------------------------------+



More information about the jdom-interest mailing list