简体   繁体   中英

Schema validation fails for xml and xsd

This is my xsd

<xs:schema id="RCDNetworkAdapterData" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:element name="RCDNetworkAdapterData">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="AdapterName" minOccurs="1" nillable="false" maxOccurs="3">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:minLength value="1"/>
                    <xs:maxLength value="3"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:element>       
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

And this is the xml that maps to it:

<RCDNetworkAdapterData>
  <AdapterName>Ethernet</AdapterName>
  <AdapterName>WI-FI</AdapterName>
</RCDNetworkAdapterData> 

Please help in modifying the xsd to map to the xml structure

With Saxon as the schema validator I get the error messages:

Validation error on line 2 column 39 of test.xml:
  FORG0001: The content "Ethernet" of element <AdapterName> does not match the required
  simple type. Value "Ethernet" contravenes the maxLength facet "3" of the type of element AdapterName
  See http://www.w3.org/TR/xmlschema-2/#cvc-datatype-valid clause 1
Validation error on line 3 column 36 of test.xml:
  FORG0001: The content "WI-FI" of element <AdapterName> does not match the required simple
  type. Value "WI-FI" contravenes the maxLength facet "3" of the type of element AdapterName
  See http://www.w3.org/TR/xmlschema-2/#cvc-datatype-valid clause 1

Hopefully these messages are clear: you have constrained the values of the AdapterName to be 1 to 3 characters, and your values are longer than this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM