Reputation: 924
I want to create an XML file that should be validated by two schemas (one import another):
<bbb:Order xmlns:bbb="http://NamespaceTest.com/BBB" xmlns:aaa="http://NamespaceTest.com/AAA">
<aaa:Customer>
<aaa:Name>string</aaa:Name>
<aaa:DeliveryAddress>string</aaa:DeliveryAddress>
<aaa:BillingAddress>string</aaa:BillingAddress>
</aaa:Customer>
</bbb:Order>
For this, I have created two schemas. First one looks like:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://NamespaceTest.com/AAA"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://NamespaceTest.com/AAA"
elementFormDefault="qualified">
<xs:element name="Customer" type="CustomerType">
</xs:element>
<xs:complexType name="CustomerType">
<xs:sequence>
<xs:element name="Name" type="xs:string" />
<xs:element name="DeliveryAddress" type="xs:string" />
<xs:element name="BillingAddress" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
and I import this file into the second schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://NamespaceTest.com/BBB"
xmlns:aa="http://NamespaceTest.com/AAA" targetNamespace="http://NamespaceTest.com/BBB"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import schemaLocation="aaa.xsd" namespace="http://NamespaceTest.com/AAA"/>
<xs:element name="Order">
<xs:complexType>
<xs:sequence>
<xs:element name="Customer" type="aa:CustomerType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
When I have such schemas, the element Customer in the XML file must be referenced from namespace http://NamespaceTest.com/BBB, but I want it to be referenced from http://NamespaceTest.com/AAA (where the type is defined). How the schema should be changed so I can have the XML like at the beginning of the question?
Upvotes: 0
Views: 27
Reputation: 163262
You've defined a local element bbb:Customer
when you should have referenced the global element aaa:Customer
. It should be
<xs:complexType>
<xs:sequence>
<xs:element ref="aa:Customer"/>
</xs:sequence>
</xs:complexType>
Incidentally (and a lot of people get the terminology wrong, you're not alone) you have one schema here, made up of two schema documents.
Upvotes: 1