XML 模式中的递归? [英] Recursion in an XML schema?
本文介绍了XML 模式中的递归?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要创建一个 XML 模式来验证 XML 文档的树结构.我不确切知道树的出现次数或深度级别.
I need to create an XML schema that validates a tree structure of an XML document. I don't know exactly the occurrences or depth level of the tree.
XML 示例:
<?xml version="1.0" encoding="utf-8"?>
<node>
<attribute/>
<node>
<attribute/>
<node/>
</node>
</node>
验证它的最佳方法是什么?递归?
Which is the best way to validate it? Recursion?
推荐答案
如果您需要递归类型声明,以下示例可能会有所帮助:
if you need a recursive type declaration, here is an example that might help:
<xs:schema id="XMLSchema1"
targetNamespace="http://tempuri.org/XMLSchema1.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/XMLSchema1.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema1.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
<xs:element name="node" type="nodeType"></xs:element>
<xs:complexType name="nodeType">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="node" type="nodeType"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
如您所见,这定义了一个递归模式,其中只有一个名为node"的节点,可以根据需要深入.
As you can see, this defines a recursive schema with only one node named "node" which can be as deep as desired.
这篇关于XML 模式中的递归?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文