1

私はこの質問を数回投稿したことを知っています。しかし、私は今、助けが必要な新しいエラーを受け取っています。これが私が受け取っているエラーです。"s4s-elt-invalid-content.1:'#AnonType_orders'のコンテンツが無効です。要素'element'が無効であるか、配置が間違っているか、頻繁に発生します。"

これが私のxsdファイルです:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="reach">
        <xs:restriction base = "xs:integer">
          <xs:enumeration value = "50" />
          <xs:enumeration value = "75" /> 
          <xs:enumeration value = "100" />
         </xs:restriction>
 </xs:simpleType>
<xs:simpleType name = "language">
    <xs:restriction base = "xs:string">
        <xs:enumeration value = "Spanish" />
        <xs:enumeration value = "Chinese" />
        <xs:enumeration value = "English" />
        <xs:enumeration value = "German" />
        <xs:enumeration value = "French" />
     </xs:restriction>
   </xs:simpleType>
<xs:simpleType name="caseColor">
    <xs:restriction base="xs:string">
        <xs:enumeration value="Lemonde" />
        <xs:enumeration value="Strawberry" />
        <xs:enumeration value="Lime" />
        <xs:enumeration value="Blueberry" />
    </xs:restriction> 
  </xs:simpleType>
<xs:simpleType name="numOfBat">
    <xs:restriction base="xs:integer">
        <xs:enumeration value="1" />
        <xs:enumeration value="2" />
        <xs:enumeration value="3" />
        <xs:enumeration value="4" />
    </xs:restriction> 
  </xs:simpleType>
<xs:simpleType name="numOfCam">
    <xs:restriction base="xs:string">
        <xs:pattern value="1|2" />
    </xs:restriction> 
  </xs:simpleType>
<xs:simpleType name="volt">
    <xs:restriction base="xs:string">
        <xs:enumeration value="110-120" />
        <xs:enumeration value="220-240" />
    </xs:restriction> 
  </xs:simpleType>
<xs:element name="orders">
<xs:complexType>
<xs:element name ="order" maxOccurs="unbounded"> 
<xs:complexType>
 <xs:sequence>
    <xs:element name="custName" type ="xs:string" />
                <xs:attribute name ="custID" />
<xs:element name="case" type="xs:caseColor" >
</xs:element>
<xs:element name="batteries" type="xs:numOfBat" default = 
"1"> 
</xs:element>
<xs:element name="recharger" type="xs:volt" /> 
<xs:element name="arm"> 
   <xs:element name ="reaches" minOccurs="2" maxOccurs="3" 
type="xs:reach" />
</xs:element>
<xs:element name ="camera" type="xs:numOfCam" /> 
<xs:element name = "speech" type="xs:language" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:complexType>
</xs:element>
</xs:schema>

これが私のxmlファイルです:

<?xml version="1.0" encoding="UTF-8"?>
<orders>
<order>
<custName custID="11223"> John Doe </custName>
<case> Strawberry </case>
<batteries> 2 </batteries>
<recharger> 110-120 V </recharger>
<arm>  
   <reach> 50 </reach>
   <reach> 100 </reach>
</arm>
<camera> 2 </camera>
<speech> Spanish </speech>
</order>
<order>
<custName custID="45392"> Jane Camp </custName>
<case> Lime </case>
<batteries> 4 </batteries>
<recharger> 220-240 V </recharger>
<arm> 3
   <reach> 75 </reach>
   <reach> 75 </reach>
   <reach> 100 </reach>
</arm>
<camera> 1 </camera>
<speech> Chinese </speech>
</order>
<order>
<custName custID="69482"> George Carlton </custName>
<case> Blueberry </case>
<batteries> 1 </batteries>
<recharger> 110-120 V </recharger>
<arm> 
   <reach> 75 </reach>
   <reach> 100 </reach>
</arm>
<camera> 2 </camera>
<speech> French </speech>
</order>
</orders>
4

2 に答える 2

3

あなたの形、特にあなたの要素xsdが悪いです。ordersまた、カスタム タイプの間違った名前空間を参照しています。私は私が見る問題を実行します。

最初:ordersノードは として定義されており、 の子として要素xs:complexTypeがありますが、要素は許可された子ノードではありません。または間に入れる必要があります:ordercomplexTypexs:sequencexs:all

<xs:element name="orders">
  <xs:complexType>
    <xs:sequence>
      <xs:element name ="order" maxOccurs="unbounded">
         <!-- existing nodes -->
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element>

次へ: あなたのarm要素には 1 つの子要素がxs:elementありますが、このコンテキストでは許可されていません。complexTypeand then sequenceor allagainとして定義する必要があります。

<xs:element name="arm">
    <xs:complexType>
        <xs:sequence>
            <xs:element name ="reaches" minOccurs="2" maxOccurs="3" type="reach" />
        </xs:sequence>
    </xs:complexType>
</xs:element>

3 番目:custId属性が正しい場所で定義されていません。 xs:attributes属性として定義されている要素の下に子ノードとして定義する必要がありますが、xs:simpleType は属性ノードを持つことができないため、代わりにそれを complexType として定義する必要があります。ここであなたの問題に対する可能な解決策は次のとおりです。

<xs:element name="custName">
    <xs:complexType>
        <xs:simpleContent>
            <xs:extension base="xs:string">
               <xs:attribute name="custID" type="xs:int" use="required" />
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
</xs:element>

最後に、すべてのカスタム タイプ ( reachnumOfBatvoltなど) を参照する場合、xs:名前空間の一部としてそれらを参照していますが、これらのタイプは名前空間で定義されていませんxs:。XSD の targetNamespace を定義しないため、カスタム型はデフォルトの名前空間の一部になります。xs:タイプから を削除するだけです。

たとえば、次のように宣言する必要があります: type="reach"type="numOfBat"type="caseColor"など

于 2012-04-11T14:41:30.963 に答える
0

検証にどのツールを使用しているかはわかりませんが、生成されるメッセージは役に立たないようです。情報については、Saxon によって生成されるメッセージを次に示します。

Saxon-EE 9.5.0.1J from Saxonica
Java version 1.6.0_27
Using license serial number M008277
Loading schema document file:/Users/mike/Desktop/temp/test.xsd
Error at xs:element on line 48 column 49 of test.xsd:
  Element xs:element cannot appear here: expected one of {choice, sequence, assert,
  openContent, annotation, attributeGroup, anyAttribute, simpleContent, all, attribute,
  group, complexContent}
Error at xs:attribute on line 52 column 48 of test.xsd:
  Element <xs:attribute> is not allowed as a child of <xs:sequence>
Error at xs:element on line 61 column 19 of test.xsd:
  Element xs:element cannot appear here: expected one of {annotation, simpleType, key,
  complexType, keyref, unique, alternative}
Error at xs:element on line 61 column 19 of test.xsd:
  Element <xs:element> is not allowed as a child of <xs:element>
Schema processing failed: 4 errors were found while processing the schema

これらがより明確になることを願っています。基本的に、問題は xs:element が xs:complexType の子として表示されないことです。おそらく間に xs:sequence のようなものが必要です。

于 2012-04-09T18:19:01.063 に答える