s4s-elt-invalid-content.1:内容无效。元素'属性'无效,放错位置或过于频繁发生

时间:2017-05-16 18:01:46

标签: xml xsd xsd-validation xml-validation

我正在为一个项目开发一个XSD,这就是我所拥有的:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
targetNamespace="http://www.example.org/Elizabeth schema" 
xmlns:elz="http://www.example.org/Elizabeth_schema" elementFormDefault="qualified">
<xs:element name ="year">
<xs:complexType mixed = "true">
<xs:sequence>
<xs:element name="entry">
    <xs:complexType mixed ="true">
    <xs:simpleContent>
        <xs:attribute name ="when" type = "xs:string"/> 
        <xs:attribute name = "place" type = "xs:string"/>
        <xs:element name = "items" type = "xs:string"/>
        <xs:element name = "characters">
            <xs:complexType>
            <xs:attribute name ="character" type = "xs:string"/>
            </xs:complexType>
        </xs:element>
        <xs:element name = "eventscollection">
            <xs:complexType>
            <xs:attribute name = "type" type = "xs:string"/>
            </xs:complexType>
        </xs:element>
        <xs:element name ="entrytxt">
            <xs:complexType>
            <xs:any minOccurs = "0"/>
            <xs:anyAttribute minOccurs="0"/>
            </xs:complexType>
        </xs:element>
        </xs:simpleContent>
    </xs:complexType>
    </xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

我还没有将xls指向架构,因为我想先让架构运行。我的IDE给我一个错误:

  

s4s-elt-invalid-content.1:'#AnonType_entryyear'的内容是   无效。元素“属性”无效,错位或发生   常。

第11行是我在元素“entry”下引入第一个属性的地方。我发现如果我删除第10行(“simpleContent”),我会得到相同的错误,但在第13行,我在“entry”下引入了第一个元素。

我是这个的初学者,我在互联网上做了一些刺激,但似乎无法弄清楚我的代码是什么。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您的XSD存在许多问题,包括

  • entry没有简单的内容。将xs:simpleContent更改为 xs:sequence内的xs:complexType
  • 然后,将xs:attribute声明移到xs:sequence之外。
  • minOccurs移除xs:anyAttribute

请注意,您可能希望删除属性=符号周围的间距 - 不是必需的,但它看起来非常规,并且与您一样不一致。

以下是您的XSD完全更正:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
           targetNamespace="http://www.example.org/Elizabeth schema"
           xmlns:elz="http://www.example.org/Elizabeth_schema" 
           elementFormDefault="qualified">
  <xs:element name="year">
    <xs:complexType mixed="true">
      <xs:sequence>
        <xs:element name="entry">
          <xs:complexType mixed="true">
            <xs:sequence>
              <xs:element name="items" type="xs:string"/>
              <xs:element name="characters">
                <xs:complexType>
                  <xs:attribute name="character" type="xs:string"/>
                </xs:complexType>
              </xs:element>
              <xs:element name="eventscollection">
                <xs:complexType>
                  <xs:attribute name="type" type="xs:string"/>
                </xs:complexType>
              </xs:element>
              <xs:element name="entrytxt">
                <xs:complexType>
                  <xs:sequence>
                    <xs:any minOccurs="0"/>
                  </xs:sequence>
                  <xs:anyAttribute/>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
            <xs:attribute name="when" type="xs:string"/> 
            <xs:attribute name="place" type="xs:string"/>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>