XML模式属性问题
如何使XML模式接受元素的两个属性 例如,在XML文件中声明:XML模式属性问题,xml,xsd,xmllint,Xml,Xsd,Xmllint,如何使XML模式接受元素的两个属性 例如,在XML文件中声明: <list1_City City="Newcastle" Year="1999"> .... .... .... .... </list1_City> .... .... .... .... 我一直在尝试这样编写XSD: <xs:element name="list1_City"> <xs:complexType> <xs:attribute name="City" typ
<list1_City City="Newcastle" Year="1999">
....
....
....
....
</list1_City>
....
....
....
....
我一直在尝试这样编写XSD:
<xs:element name="list1_City">
<xs:complexType>
<xs:attribute name="City" type="xs:string" use="required">
<xs:attribute name="Year" type="xs:integer" use="required">
....
....
....
....
</xs:attribute>
</xs:attribute>
</xs:complexType>
</xs:element>
....
....
....
....
我还尝试将属性分组为
每次我尝试用XMLLINT验证它时,它都会抛出如下错误:
<xs:element name="list1_City">
<xs:complexType>
<xs:attribute name="City" type="xs:string" use="required">
<xs:attribute name="Year" type="xs:integer" use="required">
....
....
....
....
</xs:attribute>
</xs:attribute>
</xs:complexType>
</xs:element>
sample2.xsd:15:element属性:架构分析器错误:元素“{}属性”:内容无效。应为(注释?、simpleType?)。
WXS架构sample2.xsd未能编译
有什么想法吗
/保罗
谢谢你,马丁。它似乎已经通过了这些验证行,但它相当复杂,因为元素直到XML文件结束时才关闭,而且中间有许多嵌套元素。那么,在模式中处理所有嵌套元素(标记为………..)之前,是否应该关闭所有元素(属性、complexType和元素)?好像我用一个字母把元素合上了
</xs:element>
那么,模式如何验证下的元素呢
<list1_City City="Newcastle" Year="1999">, such as
<List2><list1_Year_Collection><list1_Year><matrix1>
<matrix1_Type_Collection>
,例如
…等等…直到它以
</list1_City>
?不要嵌套
xs:attribute
元素,将它们分开放置,例如
<xs:element name="list1_City">
<xs:complexType>
<xs:attribute name="City" type="xs:string" use="required"/>
<xs:attribute name="Year" type="xs:integer" use="required"/>
</xs:complexType>
</xs:element>
我编辑了我的答案,以展示如何定义复杂类型的元素内容的示例。