嵌入式schematron不能在具有命名空间的XML文档中工作
问题描述:
我正在玩一些XSD文件中嵌入的schematron规则。这个例子是规范的例子之一,它在没有名称空间的情况下工作,但是当我引入一个名称空间时,它会停止验证,我无法弄清楚为什么。嵌入式schematron不能在具有命名空间的XML文档中工作
的模式很简单:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://me.com/ns" xmlns:q="http://me.com/ns">
<xs:element name="socket">
<xs:annotation>
<xs:appinfo>
<sch:pattern name="Mutually exclusive attributes on the socket element"
xmlns:sch="http://purl.oclc.org/dsdl/schematron">
<sch:rule context="socket" >
<sch:assert test="@hostName and @hostAddress">On a socket element only one
of the attributes hostName and hostAddress are allowed, not
both.</sch:assert>
</sch:rule>
</sch:pattern>
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:attribute name="hostName" type="xs:string" use="optional"/>
<xs:attribute name="hostAddress" type="xs:string" use="optional"/>
</xs:complexType>
</xs:element>
</xs:schema>
和被确认的文档是:当被删除的命名空间
<?xml version="1.0" encoding="UTF-8"?>
<socket xmlns="http://me.com/ns" hostAddress="192.168.200.76"/>
的Schematron的断言解雇,但如上图所示,他们不这样做。我尝试在上下文中引用命名空间<sch:rule context="q:socket">
,但是随后出现了schematron管道的编译错误。
有没有人知道他们的头顶如何解决这个问题?
答
这是一个更新的XSD,将工作:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://me.com/ns" targetNamespace="http://me.com/ns" xmlns:sch="http://purl.oclc.org/dsdl/schematron">
<xs:annotation>
<xs:appinfo>
<sch:ns uri="http://me.com/ns" prefix="q"/>
</xs:appinfo>
</xs:annotation>
<xs:element name="socket">
<xs:annotation>
<xs:appinfo>
<sch:pattern name="Mutually exclusive attributes on the socket element" xmlns:sch="http://purl.oclc.org/dsdl/schematron">
<sch:rule context="q:socket">
<sch:assert test="@hostName and @hostAddress">On a socket element only one
of the attributes hostName and hostAddress are allowed, not
both.</sch:assert>
</sch:rule>
</sch:pattern>
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:attribute name="hostName" type="xs:string" use="optional"/>
<xs:attribute name="hostAddress" type="xs:string" use="optional"/>
</xs:complexType>
</xs:element>
</xs:schema>
的Schematron需要命名空间前缀声明如上所示。
我将scheme元素更改为',但是assert仍然无法触发。 –
2013-05-02 16:15:38
Aha,工作,但我不得不限定属性''。谢谢:) –
2013-05-03 06:28:30
我已经尝试了注释的XSD和提供的XML,如图所示,它们按所述方式工作。按照模式,这些属性不需要限定,所以你必须尝试过别的。 – 2013-05-03 10:54:56