[jdom-interest] JDOM SAXBuilder validation schema with Java

Christian Avril christian.avril at dpma.finances.gouv.fr
Mon Dec 27 07:12:38 PST 2004

JDOM SAXBuilder validation schema
Does somebody know if we are obliged to mention the name of the schema xsd just inside of the file XML ?
OR if we can place it only in the program Java ?

For example in Java,
when I use only the builder.setFeature() ... it'works very well, because the name and the path of the schema xsd 
is already written in the XML file, and I don't need to use the builder.setProperty()  : 

    SAXBuilder builder =  new SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
    builder.setFeature("http://apache.org/xml/features/validation/schema", true);
    // builder.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",
    //                    "file:///C:/Projets/Jdom-1-0/xml/countries.xsd");

File countries.xml
<?xml version="1.0" encoding="UTF-8"?>
<countries xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="countries.xsd">     <!-- the name of my schema is in the file XML ! -->
 <country name="England" capital="London"/>
 <country name="Wales" capital="Cardiff"/>
 <country name="Scotland" capital="Edinburgh"/>

File countries.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
 <xs:element name="countries">
   <xs:sequence minOccurs="0" maxOccurs="unbounded">
    <xs:element ref="country"/>
 <xs:element name="country">
   <xs:attribute name="name" type="xs:string" use="required"/>
   <xs:attribute name="capital" type="xs:string" use="required"/>

But, if I don't want to have the name of the schema reference into the XML file, but only in the java program, 
how Can I do ? I think I need the builder.setProperty() 
But if I delete the name of the schema from the XML file, I have the error : 
Error on line 3 of document file:///C:/Projets/Jdom-1-0/xml/countries.xml: 
cvc-elt.1: Cannot find the declaration of element 'countries'.

And I know there is no problem with the path C:/Projets/Jdom-1-0/xml/countries.xml

Can somebody help ?

Thank's in advance
I hope this problem can help somebody

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20041227/d709c0a7/attachment.htm

More information about the jdom-interest mailing list