EDN Admin
Well-known member
Guarding inline dictionaries in XSD - to prevent duplicate keys<br/>
<br/>
Hi all, <br/>
<br/>
is it possible to, in an XSD, to guard inline dictionaries so that they can contain duplicate key values?<br/>
<br/>
<br/>
This is what I currently have, but because the structure is a dictionary and adding duplicate entries causes the dictionary to thrown an invalid operation exception during deserialization<br/>
<br/>
<xs:complexType name="CompanyReferences <br/>
<xs:sequence><br/>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Company <br/>
<xs:complexType><br/>
<xs:simpleContent><br/>
<xs:extension base="xs:string <br/>
<xs:attribute name="key" type="xs:string" use="required"/><br/>
</xs:extension><br/>
</xs:simpleContent><br/>
</xs:complexType><br/>
</xs:element><br/>
</xs:sequence><br/>
</xs:complexType><br/>
<br/>
I know you can use xs:unique for Normal dictionaries, but I cant seem to get xzs:unique to work with inline dictionaries.<br/>
<br/>
This is what I have found so far...<br/>
<br/>
If I have two dictionaries, one inline and one normal...<br/>
<br/>
<?xml version="1.0" encoding="utf-8"?><br/>
<root xmlns="http://tempuri.org/ <br/>
<InlineDictionaryItem key="1 asd</InlineDictionaryItem><br/>
<InlineDictionaryItem key="1 qwe</InlineDictionaryItem><br/>
<InlineDictionaryItem key="2"/><br/>
<NormalDictionary><br/>
<NormalDictionaryItem key="0 asd</NormalDictionaryItem><br/>
<NormalDictionaryItem key="0 qwe</NormalDictionaryItem><br/>
<NormalDictionaryItem key="5"/><br/>
</NormalDictionary><br/>
</root><br/>
<br/>
I can use xs:unique on the normal dictionary but not the inline...<br/>
<br/>
<?xml version="1.0" encoding="utf-8"?><br/>
<xs:schema xmlns:mstns="http://tempuri.org/" <br/>
xmlns="http://tempuri.org/" <br/>
elementFormDefault="qualified" <br/>
targetNamespace="http://tempuri.org/" <br/>
xmlns:xs="http://www.w3.org/2001/XMLSchema <br/>
<xs:complexType name="ClassDictionary <br/>
<xs:sequence><br/>
<xs:element minOccurs="0" maxOccurs="unbounded" name="InlineDictionaryItem <br/>
<xs:complexType><br/>
<xs:simpleContent><br/>
<xs:extension base="xs:string <br/>
<xs:attribute name="key" type="xs:int" use="required" /><br/>
</xs:extension><br/>
</xs:simpleContent><br/>
</xs:complexType><br/>
<!-- We need something something like this working for such a sequence declaration in order to quard inline dictionaries that are used in GGS --><br/>
<xs:unique name="Constraint1 <br/>
<xs:selector xpath="."/><br/>
<xs:field xpath="@key"/><br/>
</xs:unique><br/>
</xs:element><br/>
<xs:element minOccurs="0" name="NormalDictionary <br/>
<xs:complexType><br/>
<xs:sequence><br/>
<xs:element minOccurs="0" maxOccurs="unbounded" name="NormalDictionaryItem <br/>
<xs:complexType><br/>
<xs:simpleContent><br/>
<xs:extension base="xs:string <br/>
<xs:attribute name="key" type="xs:int" use="required" /><br/>
</xs:extension><br/>
</xs:simpleContent><br/>
</xs:complexType><br/>
</xs:element><br/>
</xs:sequence><br/>
</xs:complexType><br/>
<!-- For standard dictionaries this works ok --><br/>
<xs:unique name="Constraint2 <br/>
<xs:selector xpath="mstns:NormalDictionaryItem"/><br/>
<xs:field xpath="@key"/><br/>
</xs:unique><br/>
</xs:element><br/>
</xs:sequence><br/>
</xs:complexType><br/>
<xs:element name="root" type="ClassDictionary" /><br/>
</xs:schema><br/>
<br/>
any help on this would be great as dont want to end up changing the data contract for customers.<br/>
<br/>
Thanks<br/>
<br/>
Tryst<hr class="sig Tryst
View the full article
<br/>
Hi all, <br/>
<br/>
is it possible to, in an XSD, to guard inline dictionaries so that they can contain duplicate key values?<br/>
<br/>
<br/>
This is what I currently have, but because the structure is a dictionary and adding duplicate entries causes the dictionary to thrown an invalid operation exception during deserialization<br/>
<br/>
<xs:complexType name="CompanyReferences <br/>
<xs:sequence><br/>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Company <br/>
<xs:complexType><br/>
<xs:simpleContent><br/>
<xs:extension base="xs:string <br/>
<xs:attribute name="key" type="xs:string" use="required"/><br/>
</xs:extension><br/>
</xs:simpleContent><br/>
</xs:complexType><br/>
</xs:element><br/>
</xs:sequence><br/>
</xs:complexType><br/>
<br/>
I know you can use xs:unique for Normal dictionaries, but I cant seem to get xzs:unique to work with inline dictionaries.<br/>
<br/>
This is what I have found so far...<br/>
<br/>
If I have two dictionaries, one inline and one normal...<br/>
<br/>
<?xml version="1.0" encoding="utf-8"?><br/>
<root xmlns="http://tempuri.org/ <br/>
<InlineDictionaryItem key="1 asd</InlineDictionaryItem><br/>
<InlineDictionaryItem key="1 qwe</InlineDictionaryItem><br/>
<InlineDictionaryItem key="2"/><br/>
<NormalDictionary><br/>
<NormalDictionaryItem key="0 asd</NormalDictionaryItem><br/>
<NormalDictionaryItem key="0 qwe</NormalDictionaryItem><br/>
<NormalDictionaryItem key="5"/><br/>
</NormalDictionary><br/>
</root><br/>
<br/>
I can use xs:unique on the normal dictionary but not the inline...<br/>
<br/>
<?xml version="1.0" encoding="utf-8"?><br/>
<xs:schema xmlns:mstns="http://tempuri.org/" <br/>
xmlns="http://tempuri.org/" <br/>
elementFormDefault="qualified" <br/>
targetNamespace="http://tempuri.org/" <br/>
xmlns:xs="http://www.w3.org/2001/XMLSchema <br/>
<xs:complexType name="ClassDictionary <br/>
<xs:sequence><br/>
<xs:element minOccurs="0" maxOccurs="unbounded" name="InlineDictionaryItem <br/>
<xs:complexType><br/>
<xs:simpleContent><br/>
<xs:extension base="xs:string <br/>
<xs:attribute name="key" type="xs:int" use="required" /><br/>
</xs:extension><br/>
</xs:simpleContent><br/>
</xs:complexType><br/>
<!-- We need something something like this working for such a sequence declaration in order to quard inline dictionaries that are used in GGS --><br/>
<xs:unique name="Constraint1 <br/>
<xs:selector xpath="."/><br/>
<xs:field xpath="@key"/><br/>
</xs:unique><br/>
</xs:element><br/>
<xs:element minOccurs="0" name="NormalDictionary <br/>
<xs:complexType><br/>
<xs:sequence><br/>
<xs:element minOccurs="0" maxOccurs="unbounded" name="NormalDictionaryItem <br/>
<xs:complexType><br/>
<xs:simpleContent><br/>
<xs:extension base="xs:string <br/>
<xs:attribute name="key" type="xs:int" use="required" /><br/>
</xs:extension><br/>
</xs:simpleContent><br/>
</xs:complexType><br/>
</xs:element><br/>
</xs:sequence><br/>
</xs:complexType><br/>
<!-- For standard dictionaries this works ok --><br/>
<xs:unique name="Constraint2 <br/>
<xs:selector xpath="mstns:NormalDictionaryItem"/><br/>
<xs:field xpath="@key"/><br/>
</xs:unique><br/>
</xs:element><br/>
</xs:sequence><br/>
</xs:complexType><br/>
<xs:element name="root" type="ClassDictionary" /><br/>
</xs:schema><br/>
<br/>
any help on this would be great as dont want to end up changing the data contract for customers.<br/>
<br/>
Thanks<br/>
<br/>
Tryst<hr class="sig Tryst
View the full article