Categories
Development

XSD validation error. “A Problem Was Found Starting At: Attribute”

I am validating my XSD through https://www.freeformatter.com/xml-validator-xsd.html but it throws an error

The content of sequence must match (annotation?, (element | Group | Choice | Sequence | Any)*). A problem was found starting at: Attribute

I need to make NOT NULL for the reportType. I used attribute (use="required") and tried to move the attribute out of sequence as well but it still throws an error. Any help will be appreciated.

Below is my XSD code.

<?xml version="1.0"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="missing">

  <xs:complexType>
    <xs:sequence>
      <xs:element name="missingID" type="xs:string"/>
      <xs:attribute name="reportType" use="required"/>
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:minLength value= "1"/>
          <xs:maxLength value= "255"/>
        </xs:restriction>
      </xs:simpleType>

      <xs:element name="reportDescription">
        <xs:simpleType >
          <xs:restriction base="xs:string">
            <xs:minLength value= "1"/>
            <xs:maxLength value= "255"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:element>

      <xs:element name="contact">
        <xs:simpleType >
          <xs:restriction base="xs:string">
            <xs:minLength value= "1"/>
            <xs:maxLength value= "255"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:element>

      <xs:element name="reward">
        <xs:simpleType >
          <xs:restriction base="xs:string">
            <xs:minLength value= "1"/>
            <xs:maxLength value= "255"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:element>

      <xs:element name="location">
        <xs:simpleType >
          <xs:restriction base="xs:string">
            <xs:minLength value= "1"/>
            <xs:maxLength value= "255"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:element>

      <xs:element name="photo" type="xs:base64Binary"/>
      <xs:element name="statusID" type="xs:string"/>
      <xs:element name="userID" type="xs:string"/>

      <xs:element name="created_date">
        <xs:simpleType>
          <xs:restriction base="xs:dateTime"/>
        </xs:simpleType>
      </xs:element>

    </xs:sequence>

  </xs:complexType>

</xs:element>
</xs:schema>


<?xml version="1.0" encoding="UTF-8"?>  <missing>       <missingID> m1234 </missingID>      

Missing Report
A person was missing yesterday at Manhattan around 8 P.M. 1234567891 Cash $10000 New York s1234 a1234 2019-11-29T09:00:15

Leave a Reply

Your email address will not be published. Required fields are marked *