xsd:attribute声明在全局xsd:complexType中的位置?

时间:2016-11-06 17:15:36

标签: xml xsd xsd-validation xml-validation

我想声明已定义元素的属性。我希望元素person可以有2个属性(nameid)我有这个:

<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>

我希望声明一个全局的,而不是本地的复杂类型。我对混合内容不感兴趣。

我收到的错误消息:

  

元素属性:架构解析器错误:元素&#39; {http://www.w3.org/2001/XMLSchema}序列&#39;:内容无效。预期是(注释?,(元素|组|选择|序列|任何)*)。

1 个答案:

答案 0 :(得分:0)

属性声明在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>