我想声明已定义元素的属性。我希望元素person
可以有2个属性(name
,id
)我有这个:
<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;:内容无效。预期是(注释?,(元素|组|选择|序列|任何)*)。
答案 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>