[jdom-interest] How to validate xml using xsd?

David Delbecq delbd at oma.be
Tue Sep 19 05:05:25 PDT 2006


Hi

i am using the code below to validate an xml using an xsd. The
corresponding xml and xsd have been attached. Despit the xml being valid
according to my editor, which validates against the xsd, i keep getting
this error with jdom:
org.jdom.input.JDOMParseException: Error on line 3: cvc-elt.1: Cannot
find the declaration of element 'email'.

As far as i know, my xsd is valid as well as the xml. Is there something
more i need to do in my code to have validation successfull?

code:
public void testXmlFormat() {
       
        SAXBuilder builder = new SAXBuilder(true);
        builder.setEntityResolver(new EntityResolver() {
       
            public InputSource resolveEntity(String publicId, String
systemId)
                    throws SAXException, IOException {
                //code to return the resource corresponding to
http://truc.much.com/email.xsd and printing on stderr the full url to
resource
                //return null for other systemId;
            }
       
        });
        try {
            builder.setProperty( JAXPConstants.JAXP_SCHEMA_LANGUAGE,
                    JAXPConstants.W3C_XML_SCHEMA );
            InputStream source =
getClass().getClassLoader().getResourceAsStream("email.xml");
            InputSource is = new InputSource(source);
            builder.build(is);
        } catch (JDOMException e) {
            e.printStackTrace();
            fail("Exception thrown: "+e);
        } catch (IOException e) {
            e.printStackTrace();
            fail("Exception thrown: "+e);
        }
    }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: email.xml
Type: text/xml
Size: 195 bytes
Desc: not available
Url : http://www.jdom.org/pipermail/jdom-interest/attachments/20060919/50376076/email.xml
-------------- next part --------------
A non-text attachment was scrubbed...
Name: email.xsd
Type: text/xml
Size: 376 bytes
Desc: not available
Url : http://www.jdom.org/pipermail/jdom-interest/attachments/20060919/50376076/email-0001.xml


More information about the jdom-interest mailing list