V
Victor
Hi, I have some sample XML and an XSD below I have written.
The XSD almost does what I want. What I need is some way of enforcing
that AT LEAST TWO of the attributes "TestAttribute" are "X".
Can this be done and if so how?
Thank you
Victor
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="TestXML">
<xs:complexType>
<xs:sequence minOccurs="2" maxOccurs="4">
<xs:element name="TestElement">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="TestAttribute" type="xs:string"
use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XML that is valid, 2 TestAttribute="X" (2 satisfies "AT LEAST TWO")
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<TestXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\test.xsd">
<TestElement TestAttribute="3">Mark</TestElement>
<TestElement TestAttribute="5">Peter</TestElement>
<TestElement TestAttribute="X">John</TestElement>
<TestElement TestAttribute="X">Luke</TestElement>
</TestXML>
XML that is valid, 3 TestAttribute="X" (3 satisfies "AT LEAST TWO")
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<TestXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\test.xsd">
<TestElement TestAttribute="3">Mark</TestElement>
<TestElement TestAttribute="X">Peter</TestElement>
<TestElement TestAttribute="X">John</TestElement>
<TestElement TestAttribute="X">Luke</TestElement>
</TestXML>
XML that does not conform to the modified schema above
1 TestAttribute="X" (1 DOES NOT satisfy "AT LEAST TWO")
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<TestXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\test.xsd">
<TestElement TestAttribute="3">Mark</TestElement>
<TestElement TestAttribute="5">Peter</TestElement>
<TestElement TestAttribute="7">John</TestElement>
<TestElement TestAttribute="X">Luke</TestElement>
</TestXML>
The XSD almost does what I want. What I need is some way of enforcing
that AT LEAST TWO of the attributes "TestAttribute" are "X".
Can this be done and if so how?
Thank you
Victor
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="TestXML">
<xs:complexType>
<xs:sequence minOccurs="2" maxOccurs="4">
<xs:element name="TestElement">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="TestAttribute" type="xs:string"
use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XML that is valid, 2 TestAttribute="X" (2 satisfies "AT LEAST TWO")
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<TestXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\test.xsd">
<TestElement TestAttribute="3">Mark</TestElement>
<TestElement TestAttribute="5">Peter</TestElement>
<TestElement TestAttribute="X">John</TestElement>
<TestElement TestAttribute="X">Luke</TestElement>
</TestXML>
XML that is valid, 3 TestAttribute="X" (3 satisfies "AT LEAST TWO")
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<TestXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\test.xsd">
<TestElement TestAttribute="3">Mark</TestElement>
<TestElement TestAttribute="X">Peter</TestElement>
<TestElement TestAttribute="X">John</TestElement>
<TestElement TestAttribute="X">Luke</TestElement>
</TestXML>
XML that does not conform to the modified schema above
1 TestAttribute="X" (1 DOES NOT satisfy "AT LEAST TWO")
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<TestXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\test.xsd">
<TestElement TestAttribute="3">Mark</TestElement>
<TestElement TestAttribute="5">Peter</TestElement>
<TestElement TestAttribute="7">John</TestElement>
<TestElement TestAttribute="X">Luke</TestElement>
</TestXML>