Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] XSD Schema and Validation problems

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Elliotte Harold <elharo AT metalab.unc.edu>
  • To: peter murray-rust <pm286 AT cam.ac.uk>
  • Cc: 'xom-interest' <xom-interest AT lists.ibiblio.org>
  • Subject: Re: [XOM-interest] XSD Schema and Validation problems
  • Date: Mon, 19 Dec 2005 08:26:15 -0500

peter murray-rust wrote:

Under XOM I have at least two problems:

(A) the *.xml files with schema references fail to parse under XOM even if no validation is called for. a typical message is:
nu.xom.ParsingException: Illegal path character
which appears to have a significant whitespace character if I write it as:
[nu.xom.ParsingException: Illegal path character ] in [C:\pmr\schema23\examples\xsd\countType1.xml]
None of my files have whitespace characters in their names but temporary filenames might have. I can remove this error simply by removing the xsi:schemaLocation attribute.

This one's hard to debug remotely, but I'm reasonably confident that it has something to do with relative URLs and Windows file paths (which aren't URLs.) If you can drop ti down to a self-contained reproducible test case, I could investigate further. It's probably not a XOM bug as such, but if the error message is unclear and unhelpful, I might be able to improve that.

(B) I have tried to switch on validation using the example in the FAQ:
System.out.println(" === xom+Xerces validation: "+file+" ====");
Document doc = null;
try {
XMLReader xerces = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
xerces.setFeature("http://apache.org/xml/features/validation/schema";, true);
Builder parser = new Builder(xerces, /*true*/ false );
doc = parser.build(new FileReader(file));
} catch (Exception e) {
fail("should not throw "+e);
...
and I get errors of the following sort:

[Warning] :5:2: schema_reference.4: Failed to read schema document 'cml0.xsd', 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>.

This error message comes from Xerces. See http://issues.apache.org/jira/browse/XERCESJ-1124 which I just filed. However your specific problem (50% certainty) is using a FileReader. Don't do that. FileReaders don't know where they came from and thus cannot resolve relative URLs. Plus they're more likely to get the encoding wrong than right. Instead try this:

doc = parser.build(file);

and see if that works.

[Error] :5:2: cvc-elt.1: Cannot find the declaration of element 'c:cml'.
[Warning] :6:32: schema_reference.4: Failed to read schema document 'cml0.xsd', 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>.

Probably the same issue.


--
Elliotte Rusty Harold elharo AT metalab.unc.edu
XML in a Nutshell 3rd Edition Just Published!
http://www.cafeconleche.org/books/xian3/
http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim




Archive powered by MHonArc 2.6.24.

Top of Page