我有一个XML文件和一个XSD文件来验证。
XML文件:
<UC4Execution>
<Script>JOB_NAME</Script>
<UC4 Server="UC4.com" Client="123" UserId="123" Password="*****" >
</UC4 >
</UC4Execution>如果我先拿下来,验证就失败了。
,我希望标签在主标签内是灵活的。我应该如何管理/验证它
XSD文件:
<xs:element name="UC4Execution">
<xs:complexType>
<xs:sequence>
<xs:element name="Script" type="xs:string"/>
<xs:element name="UC4" minOccurs="0">
<xs:complexType>
<xs:attribute name="Server" type="xs:string" use="required"/>
<xs:attribute name="Client" type="xs:string" use="required"/>
<xs:attribute name="UserId" type="xs:string" use="required"/>
<xs:attribute name="Password" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>可能会有什么问题?
发布于 2014-01-10 12:42:37
如果您希望允许订单Script, UC4和UC4, Script,那么使用xs:all而不是xs:sequence。
发布于 2014-01-10 12:45:24
如果您使用的是xs:all xs:sequence**,而不是xs:sequence**,,那么** UC4Execution 的子级将不会有所需的顺序:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="UC4Execution">
<xs:complexType>
<xs:all>
<xs:element name="Script" type="xs:string"/>
<xs:element name="UC4" minOccurs="0">
<xs:complexType>
<xs:attribute name="Server" type="xs:string" use="required"/>
<xs:attribute name="Client" type="xs:string" use="required"/>
<xs:attribute name="UserId" type="xs:string" use="required"/>
<xs:attribute name="Password" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>,所以这两个XML文档实例,
<UC4Execution>
<Script>JOB_NAME</Script>
<UC4 Server="UC4.com" Client="123" UserId="123" Password="*****" />
</UC4Execution>和这个:
<UC4Execution>
<UC4 Server="UC4.com" Client="123" UserId="123" Password="*****" />
<Script>JOB_NAME</Script>
</UC4Execution>将有效。
https://stackoverflow.com/questions/21044280
复制相似问题