Hi,
I'm trying to parse an xsd
containing import elements with schemalocations given as relative paths. The
parsing is done using an URL as argument. When generating the SchemaTypeSystem I
get the following errors:
* error: Could not load
resource "test4.xsd" (network downloads disabled).
* error: src-resolve: element '[EMAIL PROTECTED]/namespace2' not found.
* error: src-resolve: element '[EMAIL PROTECTED]/namespace2' not found.
Doing the same thing using File instead of
URL works just fine.
My code looks as follows:
private SchemaTypeSystem
generateSchemaTypeSystem(URL xsd) {
XmlObject[] schema = new XmlObject[1];
XmlOptions po = new XmlOptions();
po.setCompileDownloadUrls();
try {
schema[0] = XmlObject.Factory.parse(xsd, po);
} catch (XmlException e) {
System.out.println("[Validation:generateSchemaTypeSystem] XmlException: " + e.getCause());
e.printStackTrace();
return null;
}
catch (IOException e) {
System.out.println("[Validation:generateSchemaTypeSystem] IOException: " + e.getCause());
e.printStackTrace();
return null;
}
XmlObject[] schema = new XmlObject[1];
XmlOptions po = new XmlOptions();
po.setCompileDownloadUrls();
try {
schema[0] = XmlObject.Factory.parse(xsd, po);
} catch (XmlException e) {
System.out.println("[Validation:generateSchemaTypeSystem] XmlException: " + e.getCause());
e.printStackTrace();
return null;
}
catch (IOException e) {
System.out.println("[Validation:generateSchemaTypeSystem] IOException: " + e.getCause());
e.printStackTrace();
return null;
}
return generateSchemaTypeSystem(schema);
}
private SchemaTypeSystem
generateSchemaTypeSystem(XmlObject[] schema) {
SchemaTypeSystem sts;
Collection compErrors = new ArrayList();
XmlOptions schemaOptions = new XmlOptions();
//schemaOptions.setCompileDownloadUrls();
schemaOptions.setErrorListener(compErrors);
for(int i = 0; i < schema.length; i++) {
System.out.println("Schema no. " + i);
if(schema[i] == null) System.out.println("Schema no. " + i + " null");
}
try {
sts = XmlBeans.compileXsd(schema, XmlBeans.getBuiltinTypeSystem(), schemaOptions);
} catch (XmlException e) {
if (compErrors.isEmpty()) {
System.out.println("[Validation:generateSchemaTypeSystem] XmlException: " + e.getCause());
e.printStackTrace();
}
System.out.println("[Validation:generateSchemaTypeSystem] XmlException: " + e.getCause() + " Schema invalid");
e.printStackTrace();
for (Iterator i = compErrors.iterator(); i.hasNext();) {
System.out.println("[Validation:generateSchemaTypeSystem] XSD Error: " + i.next());
}
return null;
}
return sts;
}
SchemaTypeSystem sts;
Collection compErrors = new ArrayList();
XmlOptions schemaOptions = new XmlOptions();
//schemaOptions.setCompileDownloadUrls();
schemaOptions.setErrorListener(compErrors);
for(int i = 0; i < schema.length; i++) {
System.out.println("Schema no. " + i);
if(schema[i] == null) System.out.println("Schema no. " + i + " null");
}
try {
sts = XmlBeans.compileXsd(schema, XmlBeans.getBuiltinTypeSystem(), schemaOptions);
} catch (XmlException e) {
if (compErrors.isEmpty()) {
System.out.println("[Validation:generateSchemaTypeSystem] XmlException: " + e.getCause());
e.printStackTrace();
}
System.out.println("[Validation:generateSchemaTypeSystem] XmlException: " + e.getCause() + " Schema invalid");
e.printStackTrace();
for (Iterator i = compErrors.iterator(); i.hasNext();) {
System.out.println("[Validation:generateSchemaTypeSystem] XSD Error: " + i.next());
}
return null;
}
return sts;
}
And my xsds looks like this:
<?xml
version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="test/namespace1" xmlns:pre4="test/namespace2" targetNamespace="test/namespace1" elementFormDefault="qualified">
<xs:import namespace="test/namespace2" schemaLocation="test4.xsd"/>
<xs:element name="test3">
<xs:complexType>
<xs:sequence>
<xs:element name="elem1" type="xs:string"/>
<xs:element ref="pre4:test4"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="test/namespace1" xmlns:pre4="test/namespace2" targetNamespace="test/namespace1" elementFormDefault="qualified">
<xs:import namespace="test/namespace2" schemaLocation="test4.xsd"/>
<xs:element name="test3">
<xs:complexType>
<xs:sequence>
<xs:element name="elem1" type="xs:string"/>
<xs:element ref="pre4:test4"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<?xml
version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="test/namespace2" targetNamespace="test/namespace2" elementFormDefault="qualified">
<xs:element name="test4" type="type4"/>
<xs:simpleType name="type4">
<xs:restriction base="xs:string"/>
</xs:simpleType>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="test/namespace2" targetNamespace="test/namespace2" elementFormDefault="qualified">
<xs:element name="test4" type="type4"/>
<xs:simpleType name="type4">
<xs:restriction base="xs:string"/>
</xs:simpleType>
</xs:schema>
Does anyone know how I can solve my
problem?
Thanks in advance,
Tine

