0

I have an Xsd file

<?xml version="1.0"?>
<xs:schema id="Peoples" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:element name="Peoples">
    <xs:complexType>
      <xs:sequence minOccurs="1" maxOccurs="unbounded">
        <xs:element name="People">
          <xs:complexType>
            <xs:all>
              <xs:element name="firstname" minOccurs="1" >
                  <xs:simpleType>
                    <xs:restriction base="xs:string">
                      <xs:minLength value="1"/>
                      <xs:maxLength value="50"/>
                    </xs:restriction>
                  </xs:simpleType>       
              </xs:element>  
              <xs:element name="lastname" minOccurs="1" >
                  <xs:simpleType>
                    <xs:restriction base="xs:string">
                      <xs:minLength value="1"/>
                      <xs:maxLength value="50"/>
                    </xs:restriction>
                  </xs:simpleType>       
              </xs:element>  
             <xs:element name="midinitial" minOccurs="0">
                  <xs:simpleType>
                    <xs:restriction base="xs:string">
                      <xs:maxLength value="50"/>
                    </xs:restriction>
                  </xs:simpleType>  
              </xs:element>
              <xs:element name="email" minOccurs="0" >
                  <xs:simpleType>
                    <xs:restriction base="xs:string">
                      <xs:maxLength value="50"/>
                    </xs:restriction>
                  </xs:simpleType>  
              </xs:element> 
            </xs:all>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

and the xml file is

<Peoples xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="">
    <People>
        <firstname>James</firstname>
    </People>
</Peoples>

The xml validation it gives :1:142: cvc-complex-type.2.4.b: The content of element 'People' is not complete. One of '{lastname, midinitial, email}' is expected.

but in this the firstname and lastname is the requied field. There is a way to validate xml only required field alone

4

1 回答 1

0

您的问题不在于验证器验证不正确。你的问题是你不喜欢它的错误信息。您的选择是尝试另一个验证器,看看它是否会针对这种情况产生您更喜欢的验证消息,或者习惯错误消息有时不会告诉我们我们希望它们做什么,有时会告诉我们事情的事实我们希望他们没有。

于 2013-06-02T04:14:53.293 回答