Where does xsd:attribute declaration go in global xsd:complexType?

核能气质少年 提交于 2020-11-29 09:54:08

问题


I want to declare an attribute of an element already defined. I would like that the element person could have 2 attributes (name, id) I have this:

<xs:element name="person" type="perso" />

<xs:complexType name="perso">
 <!-- I tried to declare the attribute here.Not working-->
        <xs:sequence>
            <!-- I tried to declare the attribute here.Not working-->
            <xs:element name="description" type="xs:string" />
        </xs:sequence>
</xs:complexType>

I am looking to declare a global, not local, complex type. I am not interested in mixed content.

The error message I'm getting:

element attribute: Schemas parser error : Element '{http://www.w3.org/2001/XMLSchema}sequence': The content is not valid. Expected is (annotation?, (element | group | choice | sequence | any)*).


回答1:


Attribute declarations go after xs:sequence:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="person" type="perso" />
  <xs:complexType name="perso">
    <xs:sequence>
      <xs:element name="description" type="xs:string" />
    </xs:sequence>
    <xs:attribute name="name" type="xs:string"/>
    <xs:attribute name="id" type="xs:string"/>
  </xs:complexType>
</xs:schema>


来源:https://stackoverflow.com/questions/40452169/where-does-xsdattribute-declaration-go-in-global-xsdcomplextype

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