[jdom-interest] schema validation

TLSteinmetz at dstsystems.com TLSteinmetz at dstsystems.com
Wed May 23 14:36:26 PDT 2001

I been working through a tutorial on XML Schema by Roger L. Costello, but I
am having difficulties reproducing the xml schema format with jdom as he
describes it. An example,
<BookCatalogue xmlns="http://www.publishing.org"

Using jdom
root.addAttribute( new Attribute( "schemaLocation", "xsi",
    "http://www.publishing.org BookCatalogue.xsd" ) );

This creates

But I am unable to produce the following attribute:

When I try
root.addAttribute( new Attribute( "xmlns", "http://www.publishing.org" ) );

I receive the following exception:
org.jdom.IllegalNameException: The name "xmlns" is not legal for JDOM/XML
attributes: An Attribute name may not be "xmlns"; use the Namespace class
to manage namespaces.

I have tried all of the Attribute ctors with no luck. How can I produce
this attribute?

My next question relates to when data validation occurs. Assuming that my
root element contains a reference to an xml schema, does jdom validate the
value that is placed into the element, attribute, ?etc. during object
creation, or is validation only accomplished when an actual xml document is
created and read back into a jdom object. Example, if a referenced schema
defines dst:my_data_type as type xsd:integer, will Element el = new Element
( "dst:my_data_type" ).addContent( "xyz" ) throw an exception?

Or is this the only way to validate against a schema:
try {
  SAXBuilder builder = new SAXBuilder();
  Document doc = builder.build(new
} catch(JDOMException e){
} catch(NullPointerException e){


Travis L. Steinmetz
tlsteinmetz at dstsystems.com

More information about the jdom-interest mailing list