Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Parsing XML against multiple complex XSD

Thread Tools

Parsing XML against multiple complex XSD
Posts: n/a
Good morning

I have an XML file that I need to validate in code
The schema definition is spread accross multiple XSD files
there is 'top level' XSD that 'includes' another XSD that 'includes'
multiple other XSDs

All these are in the classpath and can be loaded like so

Source[] sources = new Source[15];

sources[0] = new
StreamSource(getClass().getClassLoader().getResour ceAsStream("schema/
sources[1] = new
StreamSource(getClass().getClassLoader().getResour ceAsStream("schema/
sources[2] = new
StreamSource(getClass().getClassLoader().getResour ceAsStream("schema/
sources[3] = new
StreamSource(getClass().getClassLoader().getResour ceAsStream("schema/
etc etc

I then create a SchemaFactory

SchemaFactory factory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCH EMA_NS_URI);

Schema schema = null;
try {
schema = factory.newSchema(sources);
catch (SAXException e) {
//throw new SchemaValidationException(e.getMessage());

This seems to work as schema is not null

However when I try to validate an XML file like so

Validator validator = schema.newValidator();
File xml = new File(.../examplectf.xml";
StreamSource ss = new StreamSource(xml

try {

Validation fails with the following validationException

cvc-elt.1: Cannot find the declaration of element 'CTfile'.

However CTFile is declared in the top level XSD

I think it may have something to do with the 'includes' however my
reading of the javadoc seems to imply that loading an array with
sources and using this to create the schema factory should combine all
the files.

Does anyone have experience og validating against multiple XSDs in
this way

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Overriding XSD locations when validating an xml document with multiple xsd references Java 0 08-25-2006 11:22 AM
Validation of XSD (XML Schema) against XSD Rushi XML 1 12-09-2005 08:12 AM
XML + XSD: Is it possible to get all errors against the XSD? Markus Java 1 11-22-2005 02:53 PM
Validating XML file against an XSD schema in an ASP.NET page simon ames ASP .Net 1 04-11-2004 09:01 AM
validating XML against an XSD string Java 0 08-29-2003 07:02 PM