如何将Schematron添加到xsd文件?



我有几个xsd文件定义了一个xml (order.xml):

. 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>

. 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>

最后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>

我想为类型*添加一个schematron,它是Customer属性之一。

<?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>

然而,我不能添加它作为另一个头。xsd,客户。xsd,产品。XSD是按顺序定义的XSD名称空间。我不能确定语法是否正确。

任何解决方案都值得赞赏。我应该怎么解它呢?我该怎么办?

您是否能够使用XSD 1.1中的xsd:assert?

:

  • https://www.w3.org/TR/xmlschema11-1/cAssertions
  • http://www.datypic.com/books/defxmlschema/chapter14.html
  • 在哪里放置XSD 1.1断言?

相关内容

  • 没有找到相关文章