具有任意数量注释的 XML 序列
好的,所以我使用 XML 模式来验证以下类型的 xml 文件:(假设括号实际上是尖括号)。
<root>
<A>
<B></B>
<C></C>
</A>
</root>
很简单->但问题是我还想要一个评论元素,它可以以任何顺序出现无限次(前提是它不是另一个评论中的评论)。因此,以下代码示例也是有效的:
<root>
<comment />
<A>
<comment />
<B>
<comment />
</B>
<comment />
<C></C>
<comment />
</A>
<comment />
</root>
最初,我对初始树施加了严格的结构 - 即 B 和 C 必须出现一次,并且 B 必须首先出现。我想不出任何方法可以用这种规模来处理更复杂的例子。有什么想法吗?
非常感谢
Alright, so I'm using XML schema to validate a following type of xml file: (just pretend the parens are actually angled brackets).
<root>
<A>
<B></B>
<C></C>
</A>
</root>
pretty simple -> except the catch is that I also want to have a comment element, which can occur an unbounded number of times in any order (provided that it isn't a comment within another comment). So the following code sample would also be valid:
<root>
<comment />
<A>
<comment />
<B>
<comment />
</B>
<comment />
<C></C>
<comment />
</A>
<comment />
</root>
Initially I had a rigid structure imposed on the initial tree - ie B and C have to appear once, and B must come first. None of the ways I can come up of doing this scale to work on more complex examples. any ideas?
Many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用扩展,如下例所示,但这只能让您在每个元素的开头添加注释。如果您希望到处都有注释,我看不到任何方法可以在不引用架构中每个序列中的注释的情况下保留序列顺序...
You could use extensions, as in the following example, but that would only let you add comments at the beginning of each element. If you want comments everywhere, I don't see any way to preserve the sequence order without referencing comments in every sequence in the schema...