XSD如何耦合两个XML元素的值?
我的程序可以返回2个XML,如:XSD如何耦合两个XML元素的值?,xml,xsd,xsd-validation,xml-validation,Xml,Xsd,Xsd Validation,Xml Validation,我的程序可以返回2个XML,如: <RESPONSE> <ERROR_ID>1</ERROR_ID> <ERROR_MESSAGE>Parse error</ERROR_MESSAGE> </RESPONSE> <RESPONSE> <ERROR_ID>2</ERROR_ID> <ERROR_MESSAGE>Unexpected attribu
<RESPONSE>
<ERROR_ID>1</ERROR_ID>
<ERROR_MESSAGE>Parse error</ERROR_MESSAGE>
</RESPONSE>
<RESPONSE>
<ERROR_ID>2</ERROR_ID>
<ERROR_MESSAGE>Unexpected attribute</ERROR_MESSAGE>
</RESPONSE>
1.
解析错误
2.
意外属性
我尝试编写一些XSD文件来验证它们是否正常。以下是我的结论:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="qualified">
<xsd:element name="RESPONSE" type="Response"/>
<xsd:complexType name="Response">
<xsd:all>
<xsd:element name="ERROR_ID" type="ErrorId"/>
<xsd:element name="ERROR_MESSAGE" type="ErrorMessage"/>
</xsd:all>
</xsd:complexType>
<xsd:simpleType name="ErrorId">
<xsd:restriction base="xsd:positiveInteger">
<xsd:enumeration value="1"/>
<xsd:enumeration value="2"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="ErrorMessage">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Parse error"/>
<xsd:enumeration value="Unexpected attribute"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
它可以很好地进行验证,但我想我是否可以将错误id与错误消息链接起来,以不让验证文件通过,其中错误id=2将与id=1的错误消息一起通过:
<RESPONSE>
<ERROR_ID>2</ERROR_ID>
<ERROR_MESSAGE>Parse error</ERROR_MESSAGE>
</RESPONSE>
2.
解析错误
有没有一个好办法?我的程序当然会返回更多的错误ID和消息
也许更好的问题是,我是否应该期待来自XSD的这种验证?XSD 1.0无法基于另一个元素的值约束一个元素的值 xsd1.1可以使用
XSD:assert
实现,但是您应该重新考虑您的设计
备选设计建议:
ERROR\u ID
-ERROR\u消息
配对<Error>1. Parse error</Error>
1。解析错误
<ParseError id="1" message="Parse error"/>
<UnexpectedAttributeError id="2" message="Unexpected attribute"/>