putting together 2 XSD

X

Xh

Hi All!

I have two simple XSD files

they are used for elements: <patient> and <address>

as standalone XML schemas - they work perfectly - validated with:
http://validate.openlaboratory.net/

I tried to put them together but they don't work.

I got errors with element <address> - maybe I'm missing something
or my XML document is invalid in a way I don't see or understand?

I got message: Element 'address' is not valid for content model:
'((lastName,birthDate),address)'

My document looks like this:

<p:patient xmlns:p="http://test/patient" xmlns:a="http://test/
address">
<p:lastName>test</p:lastName><p:birthDate>1983-03-07</p:birthDate>
<a:address>
<a:postalCode>01-111</a:postalCode>
<a:city>Wasas</a:city>
<a:street>dsdsd</a:street>
<a:country>Poland</a:country>
</a:address>
</p:patient>

This is for patient:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://test/patient"
xmlns="http://test/patient"
xmlns:addr="http://test/address"
elementFormDefault="qualified">
<xs:import namespace="http://test/address"/>
<xs:element name="patient" type="patientType"/>
<xs:element name="lastName" type="xs:string"/>
<xs:element name="birthDate" type="xs:date"/>
<xs:element name="address" type="addr:addressType"/>
<xs:complexType name="patientType">
<xs:sequence>
<xs:element ref="lastName"/>
<xs:element ref="birthDate"/>
<xs:element ref="address"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

and this is finally the address.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://test/address"
xmlns="http://test/address">
<xs:element name="address" type="addressType"/>
<xs:element name="postalCode" type="postalCodeType"/>
<xs:element name="city" type="stringMinLenght3"/>
<xs:element name="street" type="stringMinLenght3"/>
<xs:element name="country" type="stringMinLenght3"/>
<xs:simpleType name="stringMinLenght3">
<xs:restriction base="xs:string">
<xs:minLength value="3"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="postalCodeType">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{2}-[0-9]{3}"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="addressType">
<xs:sequence>
<xs:element ref="postalCode"/>
<xs:element ref="city"/>
<xs:element ref="street"/>
<xs:element ref="country"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

thanks in advance for any tips and hints

best regards
Åukasz
 
P

p.lepin

I have two simple XSD files
they are used for elements: <patient> and <address>

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://test/patient"
xmlns="http://test/patient"
xmlns:addr="http://test/address"
elementFormDefault="qualified">
<xs:import namespace="http://test/address"/>

You seem to be missing something here (and that something
seems to be the schemaLocation attribute).
<xs:element name="patient" type="patientType"/>
<xs:element name="lastName" type="xs:string"/>
<xs:element name="birthDate" type="xs:date"/>
<xs:element name="address" type="addr:addressType"/>

Absolutely no reason to do this.
<xs:complexType name="patientType">
<xs:sequence>
<xs:element ref="lastName"/>
<xs:element ref="birthDate"/>
<xs:element ref="address"/>

since you're trying to said:
</xs:sequence>
</xs:complexType>
</xs:schema>

There might be other problems with your schemata, too, but
this should solve your immediate problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top