Question

i have a xml file with schema as below . i generated a xsd validation file to validate .and now i want to add a validation that the inner text of the element Tickettype can be empty . also how can i do that?

<?xml version="1.0" encoding="utf-8" ?>
<AppStatusDetails>
  <Patronid>G5032788W</Patronid>
  <PatronidType>1</PatronidType>
  <Birthdate>19870716</Birthdate>
  <Tickettype>49</Tickettype>
</AppStatusDetails>

and i have a xsd validator file as below to validate the xml schema

<?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>

now what attribuet shoudi have to add to xsd to make the inner text of ticket type to be null

Was it helpful?

Solution

You can add nillable="true" to the 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>

And then xsi:nil="true" to Tickettype in the document instance:

<?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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top