1

I have several xsd files which defines a xml (order.xml):

Order.xsd:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
            targetNamespace="http://www.test.com/po" 
            xmlns:po="http://www.test.com/po"
            xmlns:head="http://www.test.com/header"
            xmlns:prod = "http://www.test.com/product"
            xmlns:cust = "http://www.test.com/customer">

<xsd:import namespace="http://www.test.com/product" schemaLocation="product.xsd" />
<xsd:import namespace="http://www.test.com/customer" schemaLocation="customer.xsd" />
<xsd:import namespace="http://www.test.com/header" schemaLocation="header.xsd" />
<xsd:complexType name="itemType">
<xsd:sequence>
  <xsd:element name="Item" minOccurs="1" maxOccurs="unbounded" >
    <xsd:complexType>
       <xsd:sequence>
         <xsd:element name="ItemDescription" type="prod:prodType" />
         <xsd:element name="NumberOrdered" type="xsd:integer" />
       </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="potype">
<xsd:sequence>
  <xsd:element name="Header"   type="head:headerType"  />
  <xsd:element name="Items"    type="po:itemType" />
  <xsd:element name="Customer" type="cust:customerType" />
</xsd:sequence>
</xsd:complexType>

<xsd:element name="PurchaseOrder" type="po:potype" />

</xsd:schema>

customer.xsd

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
            targetNamespace="http://www.test.com/customer" >

<xsd:complexType name="customerType">
  <xsd:sequence>
    <xsd:element name="Name"    type="xsd:string" />
    <xsd:element name="Address" type="xsd:string" />
    <xsd:element name="Phone"   type="xsd:string" />
    <xsd:element name="email"   type="xsd:string" />
  </xsd:sequence>
  <xsd:attribute name="type"    type="xsd:integer" />
</xsd:complexType>
</xsd:schema>

And lastly order.xml

<?xml version="1.0" encoding="UTF-8"?>
                    <po:PurchaseOrder xmlns:po="http://www.test.com/po">
                       <Header>
                            <Id>1</Id>
                            <date>2004-01-29</date>
                            <description>purchase order</description>
                            <value>20</value>
                            <status>shipped</status>
                       </Header>
                       <Items>
                            <Item>
                                 <ItemDescription color="red" weight="5">
                                          <Name>Widget C</Name>
                                          <SKU>1</SKU>
                                          <Price>30</Price>
                                          <Comment>no comment</Comment>
                                 </ItemDescription>
                                 <NumberOrdered>1</NumberOrdered>
                            </Item>
                       </Items>
                       <Customer type="5">
                             <Name>Manoj K Sardana</Name>
                             <Address>ring road, bangalore</Address>
                             <Phone>918051055109</Phone>
                             <email>msardana@in.ibm.com</email>
                       </Customer>
                    </po:PurchaseOrder>

I want to add a schematron for type* which is one of the Customer attributes.

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.ocle.org/dsdl/schematron" queryBinding="xslt2">
    <pattern>
        <rule context="Customer">
            <assert test"@type > 10">Type is too big</assert>
            <report test"@type > 100">Type is too big</report>
        </rule>
    </pattern>
</schema>

However I couldnt add it as the other header.xsd, customer.xsd, product.xsd which are defined in order xsd namespace. I couldn't be sure about the the correct syntax.

Any solution should be appreciated. What should be my way of solving it? What should I do?

Meric Ozcan
  • 678
  • 5
  • 25

1 Answers1