Hi,
No, you cannot do that in XML Schema alone. You can use however XML
Schema with Schematron embedded rules to check that the number of a/b
plus c/b elements inside data is less or equal to 10.
Here it is a working XML Schema with Schematron embedded rules that
does that:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="data">
<xs:annotation>
<xs:appinfo>
<pattern xmlns="http://www.ascc.net/xml/schematron" name="Check
number of occurances">
<rule context="data">
<assert test="count(a/b|c/b)<=10">The number of b
elements should be less than or equal with 10.</assert>
</rule>
</pattern>
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="a"/>
<xs:element ref="c"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="a">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="b"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="c">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="b"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="b" type="xs:string"/>
</xs:schema>
On a sample file like:
<data>
<a>
<b>...</b>
<b>...</b>
<b>...</b>
<b>...</b>
</a>
<c>
<b>...</b>
<b>...</b>
<b>...</b>
<b>...</b>
<b>...</b>
<b>...</b>
<b>...</b>
</c>
</data>
It will give:
SystemID: C:\george\workspace\oXygen\samples\test.xml
Location: 1:0
Description: The number of b elements should be less than or equal with
10. (count(a/b|c/b)<=10)
Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com