Skip to Content.
Sympa Menu

xom-interest - [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: peter murray-rust <pm286 AT cam.ac.uk>
  • To: 'xom-interest' <xom-interest AT lists.ibiblio.org>
  • Subject: [XOM-interest] XSD Schema and Validation problems
  • Date: Mon, 19 Dec 2005 10:11:44 +0000

I am trying to add XSD functionality to my CML-XOM system (JUMBO) and have run into several problems. I would appreciate any clues and hope that the description below is sufficient to give some clues. I am using XOM1.1+Eclipse3.1.1+junit+xerces+xml-api+xercesSamples on an XP system.

(a) I have constructed simple XML and XSD files of the type:
cml0.xsd:
<xsd:schema
targetNamespace="http://org.xml-cml.cml/schema";
xmlns="http://org.xml-cml.cml/schema";
xmlns:xsd="http://www.w3.org/2001/XMLSchema";
elementFormDefault="qualified"
>
<xsd:element name="cml">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="molecule" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:any processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="id"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

cml0.xml
<c:cml
xmlns:c="http://org.xml-cml.cml/schema";
xsi:schemaLocation="http://org.xml-cml.cml/schema cml0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>
<c:molecule id="a1"/>
</c:cml>
[Note - I do not like the idea of adding schema references within the XML instance but it seems to be one of the current ways of using XSD. I do not actually like XSD at all, but feel that I am constrained to use it - it solves ca 10% of validation problems in chemistry. Schematron adds somewhat more but ultimately we need much more expressive semantics.]

The example(s) validate under Xerces in the Eclipse environment (I use dom.Counter from the samples to exercise the validation:
private void xercesValidate(String file) {
System.out.println(" === xerces validation: "+file+" ====");
String[] args = {"-v", "-s", "file://"+file};
dom.Counter.main(args);
}

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.

(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>.
[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>.

I would be grateful for pointers as to how to mend this and also ways of schema validation which do not require embedding absolute or relative addresses within the XML instances. I appreciate that these problems might not occur with approaches such as RELAX-NG but I have to have an XSD offering (although I deliberately only use a small part of its functionality - it is a nightmare for non-experts and it is a pity that our ideas on XML-DEV were not heeded at the time.)

TIA

P>


Peter Murray-Rust
Unilever Centre for Molecular Sciences Informatics
University of Cambridge,
Lensfield Road, Cambridge CB2 1EW, UK
+44-1223-763069




Archive powered by MHonArc 2.6.24.

Top of Page