【发布时间】:2018-01-09 17:54:48
【问题描述】:
我正在处理一个 XSD,我需要使用断言验证同一复杂类型下的 2 个元素。
有两个元素 OpenDate 和 CloseDate。我正在使用规则
<xs:assert test="if(
xs:date(concat(
substring( OpenDate ,7 ,4 ) ,
'-',
substring( OpenDate ,1,2 ),
'-',
substring( OpenDate ,4 ,2 )) )
< xs:date(concat(
substring( ClosedDate,7,4),
'-',
substring( ClosedDate,1,2),
'-',
substring( ClosedDate,4,2))))
then true()
else false()"
saxon:message="close date cannot be a date before membership open date"/>
但这会在记录级别生成错误报告。 Xpath 显示为 Root/Record。它也不会显示错误的元素。我需要报告以显示 xpath 作为 Root/Record/OpenDate 和元素名称,而不仅仅是记录。
另外,您能否建议是否有一种方法可以在元素中使用 Assertion 来调用兄弟元素。喜欢
<xs:element name="OpenDate"
type="CMGDateFormat"
minOccurs="0"
maxOccurs="1">
<xs:annotation>
<xs:appinfo>
<format>AAAAAAA</format>
<originalName><![CDATA[MembershipOpenDate]]></originalName>
<parent> </parent>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="MembershipClosedDate"
minOccurs="0"
maxOccurs="1">
<xs:annotation>
<xs:appinfo>
<format>AAAAAAA</format>
<originalName><![CDATA[MembershipClosedDate]]></originalName>
<parent> </parent>
</xs:appinfo>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="CMGDateFormat">
<xs:assertion test="
if( xs:date(concat(
substring( $value,7 ,4 ) ,
'-',
substring( $value,1,2 ),
'-',
substring( $value,4 ,2 )) )
<
xs:date(concat(
substring( Root/Record/Opendate,7,4),
'-',
substring( Root/Record/Opendate,1,2),
'-',
substring( Root/Record/Opendate,4,2))))
then true()
else false()"
saxon:message="close date cannot be a date before membership open date"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
关于如何实现上述目标的任何建议。我想使用断言来验证两个不同的元素。
【问题讨论】:
标签: xml validation xpath xsd