Is it possible with XML schema to restrict the depth of child elements nested in a parent?
The context here is I collect alarms from a management system and I want to provide a XML document which allows the end user define some rules in order to filter the alarms into folders in the UI. I want to restrict the depth of nested folders to 3 so an end user can't nest hundreds of levels deep - as filtering to so many levels would crash the application eventually.
I could write some code to handle this, but it seems appropriate to define this in the schema if its possible.
For example, this would be fine:
<group name="Folder 1">
<group name="Folder 2">
<group name="Folder 3">
<group name="Folder 4">
</group>
</group>
</group>
</group>
This would be invalid, as Folder 5 is too deep.
<group name="Folder 1">
<group name="Folder 2">
<group name="Folder 3">
<group name="Folder 4">
<group name="Folder 5">
</group>
</group>
</group>
</group>
</group>
My schema looks like this, but its not restricting the depth for the snippet above.
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="hierarchy">
<xs:complexType>
<xs:sequence>
<xs:element name="group" type="GroupType" />
</xs:sequence>
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:complexType name="GroupType">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="group" type="GroupType" />
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="filterOn" type="xs:string" use="optional" />
<xs:attribute name="operator" type="xs:string" use="optional" />
<xs:attribute name="value" type="xs:string" use="optional" />
</xs:complexType>
</xs:schema>
Any pointers much appreciated!