验证 XML 内容时出错:元素不能包含空格.内容模型为空 [英] Error validating the XML content: The element cannot contain white space. Content model is empty

查看:42
本文介绍了验证 XML 内容时出错:元素不能包含空格.内容模型为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试验证 qti xml 文档时一直遇到此错误.这是xml文档:

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>

这是验证xml的xsd片段

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>

命名空间test.xsd"中的元素conditionvar"在命名空间test.xsd"中的子元素varequal"无效.预期的可能元素列表:不是".元素不能包含空格.内容模型为空.元素不能包含空格.内容模型为空.命名空间test.xsd"中的元素conditionvar"在命名空间test.xsd"中的子元素not"无效.预期的可能元素列表:'varequal'.

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

找到答案:

好的,我找到了答案.我改变了条件变量定义.现在它正在工作.谢谢大家的帮助

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>

感谢您的帮助.

推荐答案

根据您的架构,在您的 元素中, 是预期的.无论是哪种情况,它都可能发生零次或多次(minOccurs="0" maxOccurs="unbounded").但是, 元素必须恰好出现一次,因为没有为其设置 minOccursmaxOccurs(默认值为 <每个代码>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.

由于我不确定您打算将什么视为有效,因此我无法提供明确的更正架构片段,但我认为您实际上想要设置 minOccurs="0" maxOccurs="unbounded"对于 conditionvarThirdPartyType 中的 元素,如下所示:

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>

这篇关于验证 XML 内容时出错:元素不能包含空格.内容模型为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆