I have the following XML:
<root>
<someNode>
<someChild attr="val" />
</someNode>
<otherNode>
<otherChild>
<otherSubChild />
</otherChild>
</otherNode>
</root>
A valid XML Schema for this will be very easy. Now the problem is, my program must support a special element which is evaluated when parsing the file, and leads to conditional substitution of elements.
Example:
<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>
I think you get the idea. The thing is, the if
element is allowed to appear everywhere in the XML, but at the same time allowed to include any element which is allowed for the element it is put in.
How would I define this in a good way? Currently I am having about 90 types/elements in my XML schema, and it would be really cumbersome to manually edit every single type/element to allow an if
element which allows the correct child elements.
Is it possible to make a schema which allows the if
element as I described above?