SAXParser reading external Schema - how to add addtional namespaces
843834Jun 7 2004 — edited Jun 8 2004Hi,
I have an application where the XML-Schema has to be read from somewhere else if the XML file does not have a reference to a Schema.
Usually, my XML-file starts with:
<ODM xsi:schemaLocation="http://www.cdisc.org/ns/odm/v1.2 ODM1-2-0.xsd" xmlns="http://www.cdisc.org/ns/odm/v1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...>
Remark the extra namespace for xsi.
I am using the following code:
parser.setFeature("http://xml.org/sax/features/validation",true); // validation
parser.setFeature("http://apache.org/xml/features/validation/schema",true); // against Schema
parser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", "http://www.cdisc.org/ns/odm/v1.2 file://C:/CDISC_ODM_Checker_testfiles/ODM1.2/ODM1-2-0.xsd");
etc...
Although I am sure that the file location is correct, I get the following error when parsing:
org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'ODM'.
My Schemafile looks like:
<xs:schema targetNamespace="http://www.cdisc.org/ns/odm/v1.2" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.cdisc.org/ns/odm/v1.2" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/03/xml.xsd"/>
<xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd"/>
I am wondering what is wrong.
Does it have to do with the usual xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" that I usually have in the XML file ? Should I also tell the parser about xsi ?
Or is there anything very obvious I oversee ?
Parser is Xerces-2-5-0, Operating System is Windows 2000.
Any help is welcome
Jozef Aerts
XML4Pharma