SchemaFactory.newSchema(..)

S

slc

Hi,

I wan to validate a xml file with a xsd file.

So there istructions:


SchemaFactory sf =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

Schema schema = sf.newSchema(new File(".../file.xsd"));

But when i build new instance of schema (sf.newSchema(...))
java give this error:

org.xml.sax.SAXParseException: schema_reference.4: Failed to read
schema document XXXX', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.

I have tried with several xsd files that seem are ok.
The file path is right.

What also con be?

Thanks,

slc.
 
A

Andrew Thompson

slc wrote:
..
I wan to validate a xml file with a xsd file.

So there istructions:

..hmm. Code snippets are less helpful than an SSCCE*
SchemaFactory sf =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

Schema schema = sf.newSchema(new File(".../file.xsd"));

Exactly where is File(".../file.xsd") ?

// test the path!
File testFile = new File(".../file.xsd");
System.out.println( testFile + " testFile.exists: " + testFile.exists() );
But when i build new instance of schema (sf.newSchema(...))
java give this error:

org.xml.sax.SAXParseException: schema_reference.4: Failed to read
schema document XXXX', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.

I have tried with several xsd files that seem are ok.
The file path is right.

I doubt that. You should check it specifically, by
adding the few lines shown above.

* The SSCCE
<http://www.physci.org/codes/sscce.html>
 
A

Arne Vajhøj

slc said:
I wan to validate a xml file with a xsd file.
SchemaFactory sf =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

Schema schema = sf.newSchema(new File(".../file.xsd"));

But when i build new instance of schema (sf.newSchema(...))
java give this error:

org.xml.sax.SAXParseException: schema_reference.4: Failed to read
schema document XXXX', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.

I have tried with several xsd files that seem are ok.
The file path is right.

Are you sure about the 3 dots ?

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top