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


In reply to Re: Validating an XML file with multiple schemas by Veltro
in thread Validating an XML file with multiple schemas by mart0000

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.