Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java xml SchemaFactory - loading schema with imports with different namespaces

I have an xsd schema with following header definition

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
            targetNamespace="vdv453ger" 
            xmlns="vdv453ger" 
            xmlns:siri="http://www.siri.org.uk/siri" 
            elementFormDefault="unqualified" 
            attributeFormDefault="unqualified" 
            version="2.3e">

This file imports another xsd file:

<xsd:import namespace="http://www.siri.org.uk/siri" 
            schemaLocation="siri-1.3/siri/siri_all-v1.2.xsd"/>

The imported xsd schema has different namespace:

<xsd:schema xmlns="http://www.siri.org.uk/siri" 
            xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
            xmlns:acsb="http://www.ifopt.org.uk/acsb" 
            xmlns:ns1="http://datex2.eu/schema/1_0/1_0" 
            targetNamespace="http://www.siri.org.uk/siri" 
            elementFormDefault="qualified" 
            attributeFormDefault="unqualified" 
            version="1.2" 
            id="siri_all">

When I try to load the schema with:

SchemaFactory sf = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);
mySchema = sf.newSchema( fileUrla );

the exception is thrown:

org.xml.sax.SAXParseException: src-include.2.1: The targetNamespace of the referenced schema, currently http://www.siri.org.uk/siri, must be identical to that of the including schema, currently vdv453ger.

It complains that namespaces are different. How to fix this?

like image 754
cubesoft Avatar asked Feb 28 '26 20:02

cubesoft


1 Answers

The error message suggests to me that there is an xsd:include element that you haven't told us about. Use xsd:import for importing a schema document for a different namespace, xsd:include for a schema document for the same namespace.

like image 145
Michael Kay Avatar answered Mar 03 '26 10:03

Michael Kay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!