Element must have no character or element information item [children], because the type's content type is empty

陌路散爱 提交于 2019-12-01 17:57:37

问题


As I work on this project I keep getting an error saying:

Element 'Customer' must have no character or element information item [children], because the type's content type is empty.

I am not sure why this is not working seeing I followed the notes and it looks like this:

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

I know it's saying I can't have the type="xs:string" in there but then how do I make it have to have a string?


回答1:


You'll need to fix your XSD's definition of Customer: Use xs:simpleContent with xs:complexType rather than xsl:element/@type in your definition (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>

The above XSD will then consider content such as the following valid:

<Customer id="123">This is a string.</Customer>


来源:https://stackoverflow.com/questions/19016641/element-must-have-no-character-or-element-information-item-children-because-t

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