【发布时间】:2010-12-12 09:10:58
【问题描述】:
假设我有一个 XML 模式并希望在多个节点上支持一些扩展。扩展应该是这些节点中的有效 XML。
我知道这可以通过架构中的
以下示例使用静态扩展架构:
<xs:element name="notes" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:any namespace="http://www.w3.org/1999/xhtml"
minOccurs="0" maxOccurs="unbounded"
processContents="skip"/>
</xs:sequence>
</xs:complexType>
</xs:element>
现在我想在我的 XML 中指定这个模式,例如(我是新手),像这样:
<foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="myschema.xsd">
<bar>
<extension>
<html namespace="http://www.w3.org/1999/xhtml">
<body>Hello, World!</body>
</html>
</extension>
</bar>
</foo>
对此最好的方法是什么?理想情况下,我想在我的 XML 扩展节点中使用架构的 XML 列表。
谢谢!
== 已编辑,更详细的解释:==
我想在特定节点内支持用户定义的 XML 数据。在编写“主”架构时,我不知道这些扩展的架构。
我在我的 XSD 中指定了以下片段:
<xs:element name="extension">
<xs:complexType>
<xs:sequence>
<xs:any namespace="##other" processContents="strict"/>
</xs:sequence>
</xs:complexType>
</xs:element>
并想使用以下 XML:
<foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test.xsd" >
<bar>
<extension>
<html xmlns="http://www.w3.org/1999/xhtml">
<body2>Hello, world!</body2>
</html>
</extension>
</bar>
</foo>
现在我确实想要一个解析器错误,因为
【问题讨论】:
-
我看不到错误! XMLSpy 可能很愚蠢,不会切换名称空间。然而...... body2 在这一点上是一个无效元素!如果你拿身体怎么办?
-
查看我的编辑。 XMLSpy 拒绝 html 元素是正确的:您没有指定从哪里获取它的架构。