XML Schema属性有问题

时间:2015-11-11 14:42:57

标签: xml xsd xmllint

如何使XML Schema接受元素的两个属性?

例如,在XML文件中声明:

<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验证它时,都会抛出如下错误:

sample2.xsd:15:元素属性:架构解析器错误:元素&#39; {http://www.w3.org/2001/XMLSchema}属性&#39;:内容无效。预期是(注释?,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>

1 个答案:

答案 0 :(得分:2)

不要嵌套 Capybara.run_server = false Capybara.default_max_wait_time = 1 Capybara.javascript_driver = :webkit_with_qt_plugin_messages_suppressed Capybara::Webkit.configure do |config| config.block_unknown_urls end RSpec.configure do |config| config.include Capybara::DSL end 元素,将它们分开放置,例如。

xs:attribute

对于一般的语法,请参阅规范http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#element-complexType,根据您的需要将任何元素定义为放置<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> xs:sequencexs:choice的内容,如xs:all的孩子,例如

xs:complexType