Hello,
I need to create an xsd to validate the following type of xml:
<?xml version="1.0" encoding="UTF-8"?>
<root
<exception1 xsi:type="Excep tionAType">
<Type>1</Type>
<Info>Bla bla</Info>
</exception1>
<exception2 xsi:type="Excep tionAType">
<Type>1</Type>
<Info>Bla bla</Info>
</exception2>
<exception3 xsi:type="Excep tionBType">
<Type>2</Type>
<Info>Bla bla</Info>
</exception3>
</root>
My constraints are:
- I have a hierarchy of ExceptionType
- For all ExceptionAType, <Typemust be "1"
- For all ExceptionBType, <Typemust be "2"
With the following schema, I can validate the xml:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexTy pe abstract="true" name="Exception Type">
<xs:sequence>
<xs:element name="Type" type="xs:string "></xs:element>
<xs:element name="Info" type="xs:string "></xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexTy pe name="Exception AType">
<xs:complexCont ent>
<xs:restricti on base="Exception Type">
<xs:sequence>
<xs:element name="Type" type="xs:string " fixed="1" ></xs:element>
<xs:element name="Info" type="xs:string "></xs:element>
</xs:sequence>
</xs:restriction>
</xs:complexConte nt>
</xs:complexType>
<xs:complexTy pe name="Exception BType">
<xs:complexCont ent>
<xs:restricti on base="Exception Type">
<xs:sequence>
<xs:element name="Type" type="xs:string " fixed="2"></xs:element>
<xs:element name="Info" type="xs:string "></xs:element>
</xs:sequence>
</xs:restriction>
</xs:complexConte nt>
</xs:complexType>
<xs:complexTy pe name="RootType" >
<xs:sequence>
<xs:element name="exception 1" type="Exception Type"></xs:element>
<xs:element name="exception 2" type="Exception Type"></xs:element>
<xs:element name="exception 3" type="Exception Type"></xs:element>
</xs:sequence>
</xs:complexType>
<xs:element name="root" type="RootType" ></xs:element>
</xs:schema>
But I am not happy with that, because, I need to repeat the element
<Infoin each exception definitions.
Is there an other way of doing that, by using extension or other tricks
?
Thanks
Olivier