xml - 如何将 Schematron 添加到 xsd 文件?
问题描述
我有几个定义 xml (order.xml) 的 xsd 文件:
订单.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 命名空间定义的其他 header.xsd、customer.xsd、product.xsd。我不能确定正确的语法。
任何解决方案都应该受到赞赏。我的解决方法应该是什么?我应该怎么办?
解决方案
您可以xsd:assert
从 XSD 1.1 开始使用吗?
看:
推荐阅读
- nmap - 无法在浏览器上正确查看 Nmap XML 输出
- java - 内部类不能有静态声明 - public static final String[]
- r - R - Keras - 错误消息
- vba - Excel VBA的数据管理
- javascript - React 似乎跳过了 for 循环
- mongodb - $limit 和 $project 用于逻辑计算
- sql - 查找表中所有数值变量的均值、标准差、百分位数
- c# - aspnetcore:如何基于 URI 以编程方式调用另一个控制器?
- dll - Ada 库 GPR 项目:为什么 gprinstall 不起作用?
- scala - 在scala中递归到尾递归