简体   繁体   中英

XML Validator - XSD (XML Schema) errors

Hi I need some help to understand what happend with my schema-xml when I try to validate a simple xml

SCHEMA

enter code here
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="processconfig" type="userProcess"/>

  <xs:complexType name="userProcess">
    <xs:sequence>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="intElement" type="intElement"/>
        <xs:element name="doubleElement" type="doubleElement"/>
      </xs:choice>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="intElement">
    <xs:complexContent>
      <xs:extension base="elementWindow">
        <xs:sequence/>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="doubleElement">
    <xs:complexContent>
      <xs:extension base="elementWindow">
        <xs:sequence/>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="elementWindow" abstract="true">
    <xs:sequence>
      <xs:element name="deLabel" type="xs:string" minOccurs="0"/>
      <xs:element name="enLabel" type="xs:string" minOccurs="0"/>
      <xs:element name="key" type="xs:string" minOccurs="1"/>
      <xs:element name="mandatory" type="xs:string" minOccurs="0"/>
      <xs:element name="value" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
 </xs:schema>

I'm using inheritance, intElement and doubleElement, both extends from elementWindow and I'm trying to validate this simple xml

Xml

enter code here
<?xml version="1.0" ?>
<processconfig>
    <intElement key="count" enLabel="Count" deLabel="Anzahl"/>
</processconfig>

The result when I validate is the next:

ERRORS

Not valid.
Error - Line 3, 62: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 62; cvc-complex-type.3.2.2: Attribute 'key' is not allowed to appear in element 'intElement'.

Error - Line 3, 62: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 62; cvc-complex-type.3.2.2: Attribute 'enLabel' is not allowed to appear in element 'intElement'.

Error - Line 3, 62: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 62; cvc-complex-type.3.2.2: Attribute 'deLabel' is not allowed to appear in element 'intElement'.

Error - Line 3, 62: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 62; cvc-complex-type.2.4.b: The content of element 'intElement' is not complete. One of '{deLabel, enLabel, key}' is expected.

Any idea why? thanks!

The XSD seems to define deLabel, enLabel, key (in this order)
as sub-elements of intElement (actually as sub-elements of
its parent elementWindow), and you're trying to use them
in the XML file as attributes of intElement.

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