Error validating the XML content: The element cannot contain white space. Content model is empty

∥☆過路亽.° 提交于 2020-01-06 12:27:09

问题


Hi I keep having this error while I try to valide a qti xml document. Here is the xml document:

     <respcondition title="Correct" >
      <conditionvar>
       <not>
         <varequal respident="1">A</varequal>
       </not>
       <varequal respident="1">B</varequal>
       <not>
            <varequal respident="1">C</varequal>
       </not>
      <varequal respident="1">D</varequal>
      </conditionvar>
        <setvar action="Set">1</setvar>
       <displayfeedback linkrefid="Correct"/>
     </respcondition>

Here is the fragment of xsd that valide the xml

       <!-- ******************* -->
            <!-- ** respcondition ** -->
             <!-- ******************* -->
               <xs:complexType name="respconditionThirdPartyType">
               <xs:sequence>
                 <xs:element name="conditionvar" type="conditionvarThirdPartyType"   maxOccurs="1"/>
                 <xs:element name="setvar" type="setvarThirdPartyType" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element name="displayfeedback" type="displayfeedbackThirdPartyType" minOccurs="0" maxOccurs="unbounded"/>
              </xs:sequence>
            <xs:attribute name="title" type="xs:string"/>
      </xs:complexType>


     <!-- ****************** -->
      <!-- ** conditionvar ** -->
       <!-- ****************** -->
       <xs:complexType name="conditionvarThirdPartyType">
          <xs:sequence>
           <xs:choice>
              <xs:element name="not" type="notThirdPartyType" minOccurs="0" maxOccurs="unbounded"/>
             <xs:element name="or" type="orThirdPartyType" minOccurs="0" maxOccurs="unbounded"/>
             <xs:element name="other" type="otherThirdPartyType" minOccurs="0" maxOccurs="unbounded"/>
           </xs:choice>
        <xs:element name="varequal" type="varequalThirdPartyType" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
       </xs:complexType>

      <!-- ********* -->
        <!-- ** not ** -->
       <!-- ********* -->
      <xs:complexType name="notThirdPartyType">
          <xs:sequence>
             <xs:element name="varequal" type="varequalThirdPartyType"  minOccurs="0" maxOccurs="unbounded" />
         </xs:sequence>
       </xs:complexType>



      <!-- ************** -->
      <!-- ** varequal ** -->
      <!-- ************** -->
      <xs:complexType name="varequalThirdPartyType">
         <xs:simpleContent>
            <xs:extension base="xs:string">
               <xs:attribute name="respident" type="xs:string" use="optional"/>
               <xs:attribute name="case" default="No">
               <xs:simpleType>
           <xs:restriction base="xs:NMTOKEN">
               <xs:enumeration value="Yes"/>
              <xs:enumeration value="No"/>
          </xs:restriction>
         </xs:simpleType>
       </xs:attribute>
      </xs:extension>
     </xs:simpleContent>
     </xs:complexType>

The element 'conditionvar' in namespace 'test.xsd' has invalid child element 'varequal' in namespace 'test.xsd'. List of possible elements expected: 'not'. The element cannot contain white space. Content model is empty. The element cannot contain white space. Content model is empty. The element 'conditionvar' in namespace 'test.xsd' has invalid child element 'not' in namespace 'test.xsd'. List of possible elements expected: 'varequal'.

Please can anyone help? I've been trying to fix this for for a few days now.. Thanks Cheers

Found the answer:

Ok I've found the answer. i've changed conditionvar definition. Now it's working. Thanks you all for your help

 <!-- ****************** -->
 <!-- ** conditionvar ** -->
  <!-- ****************** -->
 <xs:complexType name="conditionvarThirdPartyType">
 <xs:sequence minOccurs="0" maxOccurs="unbounded">
  <xs:choice  minOccurs="0" maxOccurs="unbounded">
    <xs:element name="not" type="notThirdPartyType" />
    <xs:element name="or" type="orThirdPartyType" />
    <xs:element name="other" type="otherThirdPartyType" />
  </xs:choice>
  <xs:element name="varequal" type="varequalThirdPartyType"   minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>

Thanks for your help.


回答1:


According to your schema, in your <conditionvar> element, either <not> or <or> or <other> is expected. Whichever it is, it may occur zero or more times (minOccurs="0" maxOccurs="unbounded"). However, the <choice> element must be there exactly once, as minOccurs and maxOccurs aren't set for it (default value is 1 for each). This is followed by zero or more <varequal> elements.

As I am not sure what you intend to consider valid, I cannot provide a definitive corrected schema fragment, but I think that you actually want to set minOccurs="0" maxOccurs="unbounded" for your <sequence> element in conditionvarThirdPartyType, as in so:

<xs:complexType name="conditionvarThirdPartyType">
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
        <xs:choice>
            <xs:element name="not" type="notThirdPartyType"/>
            <xs:element name="or" type="orThirdPartyType"/>
            <xs:element name="other" type="otherThirdPartyType"/>
        </xs:choice>
        <xs:element name="varequal" type="varequalThirdPartyType"/>
    </xs:sequence>
</xs:complexType>


来源:https://stackoverflow.com/questions/10914431/error-validating-the-xml-content-the-element-cannot-contain-white-space-conten

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!