XML Validator - XSD(XML Schema)错误

时间:2014-03-23 09:27:06

标签: java xml validation xsd

当我尝试验证一个简单的xml时,我需要一些帮助来理解我的schema-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>

我使用继承,intElement和doubleElement,都是从elementWindow扩展而来的,我试图验证这个简单的xml

XML

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

我验证的结果是下一个:

错误

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.

知道为什么吗?谢谢!

1 个答案:

答案 0 :(得分:0)

XSD似乎定义了deLabel,enLabel,key(按此顺序)
作为intElement的子元素(实际上是作为子元素的子元素) 它的父元素窗口,你正试图使用​​它们 在XML文件中作为intElement的属性。