我有一个带有架构的xml文件,如下所示。我生成了一个xsd验证文件来验证。现在我想添加一个验证,即元素Tickettype的内部文本可以为空。我怎么能这样做?
<?xml version="1.0" encoding="utf-8" ?>
<AppStatusDetails>
<Patronid>G5032788W</Patronid>
<PatronidType>1</PatronidType>
<Birthdate>19870716</Birthdate>
<Tickettype>49</Tickettype>
</AppStatusDetails>
我有一个xsd验证程序文件,如下所示验证xml架构
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="AppStatusDetails">
<xs:complexType>
<xs:sequence>
<xs:element name="Patronid" type="xs:string" />
<xs:element name="PatronidType" type="xs:unsignedByte" />
<xs:element name="Birthdate" type="xs:unsignedInt" />
<xs:element name="Tickettype" type="xs:unsignedByte" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
现在attribuet shoudi必须添加到xsd以使票证类型的内部文本为空
答案 0 :(得分:0)
您可以将nillable="true"
添加到XSD:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="AppStatusDetails">
<xs:complexType>
<xs:sequence>
<xs:element name="Patronid" type="xs:string" />
<xs:element name="PatronidType" type="xs:unsignedByte" />
<xs:element name="Birthdate" type="xs:unsignedInt" />
<xs:element name="Tickettype" type="xs:unsignedByte" nillable="true"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
然后在文档实例中xsi:nil="true"
到Tickettype
:
<?xml version="1.0" encoding="utf-8" ?>
<AppStatusDetails xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Patronid>G5032788W</Patronid>
<PatronidType>1</PatronidType>
<Birthdate>19870716</Birthdate>
<Tickettype xsi:nil="true"></Tickettype>
</AppStatusDetails>