in reply to Validating an XML file with multiple schemas

Hello mart0000,

As people have already indicated in all the posts here, it seems that libxml has some limitations. Also googling for this confirms this as well (such as this google result)

Valid things that should be possible aren't, such as adding extra references to the xsi:schemaLocation element:

xsi:schemaLocation="urn:tempuri:Personal personal.xsd urn:tempuri:Contact email.xsd urn:tempuri:Contact address.xsd"

or adding lines to personal.xsd:

<import schemaLocation="address.xsd" namespace="urn:tempuri:Contac +t"/> <import schemaLocation="email.xsd" namespace="urn:tempuri:Contact" +/>

Multiple imports with the same namespace doesn't work

But, after some experimenting I believe I have found a a workaround. This workaround however is only going to work if you have access to the definition of personal.xsd, so I hope that that is the case:

Step 1: Create a new xsd file that 'includes' address.xsd and email.xsd with the filename 'contact.xsd' as follows:

<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:Contact="urn:tempuri:Contact" targetNamespace="urn:tempuri:Contact" elementFormDefault="unqualified"> <xs:include schemaLocation="address.xsd"/> <xs:include schemaLocation="email.xsd"/> </xs:schema>

Step 2: Change personal.xsd by adding the import line. I also added xmlns:con=..., but not sure if that was needed:

<?xml version="1.0" encoding="UTF-8"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:per="urn:tempuri:Personal" xmlns:con="urn:tempuri:Contact" targetNamespace="urn:tempuri:Personal" elementFormDefault="unqualified"> <import schemaLocation="contact.xsd" namespace="urn:tempuri:Contac +t"/> <element name="PersonalInfo"> <complexType> <sequence> <element name="FirstName" type="string"/> <element name="LastName" type="string"/> <element name="Contact" type="per:ContactType"/> </sequence> </complexType> </element> <complexType name="ContactType"> <sequence> <any namespace="##other" processContents="strict" maxOccurs="unbounded"/> </sequence> </complexType> </schema>

Step 3: Change the xml files so that they will resemble the following:

<?xml version="1.0" encoding="UTF-8"?> <pinfo:PersonalInfo xmlns:pinfo="urn:tempuri:Personal" xmlns:cinfo="urn:tempuri:Contact" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:tempuri:Personal personal.xsd"> <FirstName>First Name</FirstName> <LastName>Last Name</LastName> <Contact> <cinfo:Address> <Street>Main Street</Street> <City>Main City</City> </cinfo:Address> </Contact> </pinfo:PersonalInfo>

Even though I don't think that anything is done with xsi:schemaLocation I left it there for completeness

Hope this helps,

Veltro