【发布时间】:2017-04-13 12:07:10
【问题描述】:
我有以下 XML:
<root>
<someNode>
<someChild attr="val" />
</someNode>
<otherNode>
<otherChild>
<otherSubChild />
</otherChild>
</otherNode>
</root>
为此创建一个有效的 XML 模式将非常容易。现在的问题是,我的程序必须支持一个特殊元素,该元素在解析文件时被评估,并导致元素的条件替换。
例子:
<root>
<someNode>
<if environment="DEV">
<someChild attr="val" />
</if>
<if environment="PROD">
<someChild attr="otherVal" />
</if>
</someNode>
<otherNode>
<otherChild>
<if environment="DEV">
<otherSubChild />
</if>
</otherChild>
</otherNode>
</root>
我想你明白了。问题是,if 元素被允许出现在 XML 中的everywhere,但同时允许包含 any 元素,这是允许的元素放进去。
我该如何定义?目前,我的 XML 架构中有大约 90 种类型/元素,手动编辑每个类型/元素以允许 if 元素允许正确的子元素是非常麻烦的。
是否可以创建一个允许if 元素的架构,如上所述?
【问题讨论】: