Checking xml on xsd only to fix certain errors

I have an import file that should skip and continue certain errors. I want to ignore errors for data type, minimum length and required fields. I want to catch and display errors regarding elements that are not formatted correctly and in the wrong place.

In this case, the file contains a collection of people.

I want to catch the errors: 1: A Children node outside human node. 2: Child outside the face node. 3: Man from the side of the people node.

I want to ignore errors: 1: The child has no name. 2: A person does not have a date of birth.

<xs:element name="People">
<xs:complexType>
  <xs:sequence>
    <xs:element name="Person" minOccurs="1" maxOccurs="unbounded">
      <xs:complexType>
        <xs:all>
          <xs:element name="FirstName" minOccurs="1" maxOccurs="1">
            <xs:simpleType>
              <xs:restriction base="xs:string">
                <xs:minLength value="1"/>
              </xs:restriction>
            </xs:simpleType>
          </xs:element>
          <xs:element name="LastName" minOccurs="1" maxOccurs="1">
            <xs:simpleType>
              <xs:restriction base="xs:string">
                <xs:minLength value="1"/>
              </xs:restriction>
            </xs:simpleType>
          </xs:element>
          <xs:element name="BirthDate" type="Date" minOccurs="1" maxOccurs="1"/>              
          <xs:element name="Children">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="Child" minOccurs="1" maxOccurs="unbounded">
                  <xs:complexType>
                    <xs:all>
                      <xs:element name="FirstName" minOccurs="0" maxOccurs="1">
                        <xs:simpleType>
                          <xs:restriction base="xs:string">
                            <xs:minLength value="1"/>
                          </xs:restriction>
                        </xs:simpleType>
                      </xs:element>
                      <xs:element name="BirthDate" type="Date" minOccurs="1" maxOccurs="1"/>              
                      </xs:all>
                  </xs:complexType>
                </xs:element>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:all>
      </xs:complexType>
    </xs:element>
  </xs:sequence>
</xs:complexType>

+3
source share
2 answers

Change your schema as follows:

  • Firstname Child , type = "xs: string". , (simpleType ..). , .
  • Birthdate minOccurs 1 0.

, , . type , .

, .

XML, .

0

, , , , , , , , , . API, , , , , , . ( .)

API ( API , - /), , , ssamuel , , .

: : (1) , : , , . (2) , : , .

0

Source: https://habr.com/ru/post/1754862/


All Articles