roman has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

i am using XML::LibXML::Schema to validate XML documents against XML schemas. Recently I come across a WSDL containing in types section more than one schema element. How can I combine those related schemas into one XML::LibXML::Schema object?

I simplified those schemas to following example:

<?xml version="1.0"?>
<s:schema xmlns:s="http://www.w3.org/2001/XMLSchema"
  xmlns:s1="http://schemas.salwin-crm.com/2007/coreTypes"
  elementFormDefault="qualified"
  targetNamespace="http://schemas.salwin-crm.com/2007/webServices">
  <s:import namespace="http://schemas.salwin-crm.com/2007/coreTypes" />
  <s:element name="UploadResponse">
    <s:complexType>
      <s:sequence>
        <s:element minOccurs="1" maxOccurs="1" ref="s1:UploadResult"/>
      </s:sequence>
    </s:complexType>
  </s:element>
</s:schema>
<?xml version="1.0"?>
<s:schema xmlns:s="http://www.w3.org/2001/XMLSchema"
  xmlns:s1="http://schemas.salwin-crm.com/2007/coreTypes"
  elementFormDefault="qualified"
  targetNamespace="http://schemas.salwin-crm.com/2007/coreTypes">
      <s:element name="UploadResult" nillable="true" type="s:string"/>
</s:schema>

Parsing the first schema separately via XML::LibXML::Schema->new('string' => $str) results in quite expectable error:

Element '{http://www.w3.org/2001/XMLSchema}element', 
attribute 'ref': The QName value 
'{http://schemas.salwin-crm.com/2007/coreTypes}UploadResult'
 does not resolve to a(n) element declaration. 

The only way I found so far is to store the second schema into file and supply s:import element with schemaLocation attribute pointing to this file. But this is an adhoc cumbersome solution. I hope that there is a cleaner and more systematic one.

  • Comment on Parsing more schemas at once with XML::LibXML::Schema