как создать схему xml с помощью валидатора xsd для внутреннего текста?

у меня есть файл 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>

теперь какой атрибут нужно добавить в xsd, чтобы внутренний текст типа билета был нулевым


person subash    schedule 15.02.2014    source источник


Ответы (1)


Вы можете добавить 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>
person kjhughes    schedule 15.02.2014