我使用xsd来验证可能包含几个未知xml元素的xml文件。我知道xsd支持"any“元素来处理未知的xml元素。问题是我必须验证这些未知元素的属性,而我一直无法找到这样做的方法。
Xml虚拟示例:
<root>
<aaaaaa gui-name="my name" group="my group" chart="my chart" />
<nnnnnn gui-name="my name" group="my group" chart="my chart" />
<yyyyyy gui-name="my name" group="my group" chart="my chart" />
...
...
</root>
xml元素是未知的,但它们的属性是众所周知的。如何验证这些未知元素的属性?
提前谢谢。
发布于 2015-11-27 23:09:56
尝试使用<any>
元素类型。
请参阅http://www.w3schools.com/Xml/schema_complex_any.asp
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:any type='dummyType' />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="dummyType">
<xs:attribute name='gui-name' type='xs:string'/>
<xs:attribute name='group' type='xs:string'/>
<xs:attribute name='chart' type='xs:string'/>
</xs:complexType>
发布于 2015-11-30 09:59:06
也许你需要使用SubstitutionGroups来实现继承。请看下一个链接中的“抽象元素和代换组”这一段
发布于 2015-11-30 11:22:14
您最好更改XML格式。将标记名称移动到属性中,并对所有标记使用相同的名称。每个标记上的xsi:type属性可能能够标识包含这些属性的复杂类型的名称。你有没有考虑过这种可能性?
https://stackoverflow.com/questions/33965760
复制相似问题