验证错误“元素'元素'无效,错位或过于频繁发生”

时间:2016-08-10 05:05:43

标签: xml validation schema

由于错误,我无法验证架构。我收到的消息是“4s-elt-invalid-content.1:'#AnonType_structureplanetsolarSystem'的内容无效。元素'元素'无效,放错地方或者经常发生”。我认为这与“单元”属性在模式中的位置有关,但我无法弄明白,我现在已经在摆弄它一段时间了。任何见解?

非常感谢!! 架构:

 <?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" elementFormDefault="qualified"
    vc:minVersion="1.1">

<xs:element name="solarSystem">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="planet" minOccurs="1">
                <xs:complexType>
                    <xs:sequence>
                         <xs:element name="structure" maxOccurs="unbounded">
                             <xs:complexType>
                                 <xs:sequence>
                                     <xs:element name="name"/>
                                     <xs:element name="mass"/>
                                     <xs:element name="circumference"/>
                                     <xs:element name="polarDiameter"/>
                                     <xs:element name="AtmosComposition"/>
                                   </xs:sequence>
                                 <xs:attribute name="unit" type="xs:string"/>
                                     <xs:element name="minSurfaceTemp" type="xs:string"/>
                                     <xs:element name="maxSurfaceTemp" type="xs:string">
                                     <xs:element name="distance"/>
                                     <xs:element name="yearLength"/>
                                     <xs:element name="moonCount"/>
                                     <xs:element name="firstRecorded"/>
                                     <xs:attribute name="type" type="xs:string"/>

                                  </xs:element>
                               </xs:complexType>
                            </xs:element>
                          </xs:sequence>
                       </xs:complexType>
                     </xs:element>
                   </xs:sequence>
                </xs:complexType>
            </xs:element>
</xs:schema>

的xml:

<solarsystem>

        <planet type="terrestrial">
            <structure>
                <name>Mercury</name>
                <mass unit="kg">3.285x10^23</mass>
                <circumference>15,329</circumference>
                <polarDiameter>4,879</polarDiameter>
                <AtmosComposition>42% Oxygen, 29% Nitrogen, 22% Hydrogen, 6% Helium, 0.5 Potassium</composition>
            </structure>
            <minSurfaceTemp>-173</minSurfaceTemp>
            <maxSurfaceTemp>427</maxSurfaceTemp>
            <distance>.39 AU</distance>
            <yearLength>87.97 Earth days</yearLength>
            <moonCount>0</moonCount>
            <firstRecorded>14th Century BC</firstRecorded>
        </planet>
</solarsystem>

1 个答案:

答案 0 :(得分:2)

我是正确的,它是属性,组合,它不满意。我实际上重新做了大部分。验证架构:

    <?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
  <xs:element name="solarsystem">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" ref="planet"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="planet">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="structure"/>
        <xs:element ref="minSurfaceTemp"/>
        <xs:element ref="maxSurfaceTemp"/>
        <xs:element ref="distance"/>
        <xs:element ref="yearLength"/>
        <xs:element ref="moonCount"/>
        <xs:element ref="firstRecorded"/>
      </xs:sequence>
      <xs:attribute name="type" use="required"/>
    </xs:complexType>
  </xs:element>
  <xs:element name="structure">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="name"/>
        <xs:element ref="mass"/>
        <xs:element ref="circumference"/>
        <xs:element ref="polarDiameter"/>
        <xs:element ref="composition"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="name" type="xs:NCName"/>
  <xs:element name="mass">
    <xs:complexType mixed="true">
      <xs:attribute name="unit" type="xs:NCName"/>
    </xs:complexType>
  </xs:element>
  <xs:element name="circumference" type="xs:string"/>
  <xs:element name="polarDiameter" type="xs:string"/>
  <xs:element name="composition" type="xs:string"/>
  <xs:element name="minSurfaceTemp" type="xs:integer"/>
  <xs:element name="maxSurfaceTemp" type="xs:integer"/>
  <xs:element name="distance" type="xs:string"/>
  <xs:element name="yearLength" type="xs:string"/>
  <xs:element name="moonCount" type="xs:integer"/>
  <xs:element name="firstRecorded" type="xs:string"/>
</xs:schema>