元素必须没有字符或元素信息项[children],因为该类型的内容类型为空

2023-11-24

当我从事这个项目时,我不断收到一条错误消息:

元素“客户”必须没有字符或元素信息项 [children],因为该类型的内容类型为空。

我不确定为什么这不起作用,因为我遵循了注释,它看起来像这样:

<xs:element name="Customer" type="xs:string">  
  <xs:complexType>  
    <xs:attribute name="id" type="xs:integer" use="required"/>  
  </xs:complexType>  
</xs:element>

我知道它是在说我不能拥有type="xs:string"在那里,但是我该如何让它必须有一个字符串呢?


您需要修复 XSD 的定义Customer: Use xs:simpleContent with xs:complexType而不是xsl:element/@type在您的定义中(customer.xsd):

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           version="1.0">
  <xs:element name="Customer">
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base="xs:string">
          <xs:attribute name="id" type="xs:integer" use="required"/>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>
</xs:schema>

然后,上述 XSD 将认为以下内容有效:

<Customer id="123">This is a string.</Customer>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

元素必须没有字符或元素信息项[children],因为该类型的内容类型为空 的相关文章

随机推荐