[jdom-interest] schema validation
philip.nelson at omniresources.com
philip.nelson at omniresources.com
Thu May 24 06:09:42 PDT 2001
I think the 4 parameter constructor of Attribute is gone or deprecated.
What you are unwittingling trying to do is create a namespace as an
attribute but what you want is a namespace with a prefix of "". It always
ends up clearer to simply declare your namespaces and then add them so to
produce xmlns="http://www.publishing.org" do
Namespace defns = Namespace.getNamespace( "http://www.publishing.org");
//And now to get what you are after
Element root = new Element("BookCatalogue", defns);
Namespace xsi = Namespace.getNamespace("xsi",
"http://www.w3.org/2000/10/XMLSchema-instance");
root.addAttribute(new Attribute("schemaLocation",
"http://www.publishing.org/BookCatalogue.xsd", xsi));
> 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"
> xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
> xsi:schemaLocation=
> "http://www.publishing.org
> BookCatalogue.xsd">
>
> Using jdom
> root.addAttribute( new Attribute( "schemaLocation", "xsi",
> "http://www.w3.org/2000/10/XMLSchema-instance",
> "http://www.publishing.org BookCatalogue.xsd" ) );
>
> This creates
> xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
> xsi:schemaLocation=
> "http://www.publishing.org
> BookCatalogue.xsd"
>
> But I am unable to produce the following attribute:
> xmlns="http://www.publishing.org"
>
> 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
> File("/some/directory/sample.xml"));
> } catch(JDOMException e){
> e.printStackTrace();
> } catch(NullPointerException e){
> e.printStackTrace();
> }
>
> Thanks,
>
> Travis L. Steinmetz
> tlsteinmetz at dstsystems.com
>
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/yo
uraddr at yourhost.com
More information about the jdom-interest
mailing list