views:

19

answers:

1

I have an import file that needs to have skip and continue on specific errors. I want to ignore the errors for data type, min/max length, and required fields. I want to catch and display errors about items not formatted correctly and in the wrong location.

In this case the file contains a collection of people.

I want to catch are errors: 1: A Children node outside of a person node. 2: A Child outside of a person node. 3: A Person out side of the people node.

I want to ignore errors: 1: Child does not have a name. 2: Person does not have birth date.

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

A: 

Change your schema as follows:

  • In the Firstname element declaration under Child, add an attribute, type="xs:string". Also, remove all the content of the element declaration (simpleType and so on). You can make the tag self-closing if you want.
  • In the Birthdate element declaration, change minOccurs from 1 to 0.

The first change removes the restriction that's currently placed on the child's name that the content be at least one character long. Adding the type attribute is necessary since you're removing the current definition of the element type.

The second change tells the validator that birth date is not required.

Make those changes and the XML that you want to validate, should.

Thanks, but I want to leave those items in. I want the person creating the file to see which fields are required. But when they try to import the file I would need to ignore some of the items. The problem I am running in to is the ValidationCallBack event thats called on a validation gives no way to see what kind of error is happening. So I don't want to make changes to my schema but modify the validation call back method to be able to read and determine what error is being thrown, or only have the validation call back get called on errors that I determine to be catastrophic.
Irimis