SAXParseException: cvc-elt.1 - XSD validation

"Harris, Mark C" <[email protected]> Wed, 10 Feb 2010 08:33:59 -0000
Newsgroups gmane.text.xml.sax.general
Message-ID <8A505A82892ED246848A7BA8737999C0026105F2@EXXMAIL01.desktop.frd.metoffice.com>
Hello,

I'm trying to validate some generated XML against an XSD in a Java app
on a JBoss server. The error I'm receiving is:

"org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration
of element 'user'."

The generated XML starts like this:

<?xml version="1.0" encoding="UTF-8"?>
<user xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="User.xsd">
   <userName>...

The start of User.xsd looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="user">
...

The Java code I'm using is this:

DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document document = builder.parse(new ByteArrayInputStream(bytes));
SchemaFactory schemaFactory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(url);
Validator validator = schema.newValidator();
validator.validate(new DOMSource(document));

... where "bytes" is a byte array containing the XML that I have
generated and "url" is a URL object containing the location of my XSD
file.

I'm using Java version 1.6.0_12.

Have had a look elsewhere for reports of similar error messages but
couldn't find anything definitive on what the problem is or any
suggested solution.

Thanks for any assistance,

Mark

------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
List: [email protected]
See:  http://www.saxproject.org
https://lists.sourceforge.net/lists/listinfo/sax-users