olivier.scalbert
Usenet Archive
- Joined
- Sep 12, 2006
- Messages
- 20
- Reaction score
- 0
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="ExceptionAType">
<Type>1</Type>
<Info>Bla bla</Info>
</exception1>
<exception2 xsi:type="ExceptionAType">
<Type>1</Type>
<Info>Bla bla</Info>
</exception2>
<exception3 xsi:type="ExceptionBType">
<Type>2</Type>
<Info>Bla bla</Info>
</exception3>
</root>
My constraints are:
- I have a hierarchy of ExceptionType
- For all ExceptionAType, <Type> must be "1"
- For all ExceptionBType, <Type> must be "2"
With the following schema, I can validate the xml:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType abstract="true" name="ExceptionType">
<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:complexType name="ExceptionAType">
<xs:complexContent>
<xs:restriction base="ExceptionType">
<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:complexContent> </xs:complexType>
<xs:complexType name="ExceptionBType">
<xs:complexContent>
<xs:restriction base="ExceptionType">
<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:complexContent> </xs:complexType>
<xs:complexType name="RootType">
<xs:sequence>
<xs:element name="exception1" type="ExceptionType"></xs:element> <xs:element name="exception2" type="ExceptionType"></xs:element> <xs:element name="exception3" type="ExceptionType"></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 <Info> in each exception definitions. Is there an other way of doing that, by using extension or other tricks ?
Thanks
Olivier
I need to create an xsd to validate the following type of xml:
<?xml version="1.0" encoding="UTF-8"?>
<root
<exception1 xsi:type="ExceptionAType">
<Type>1</Type>
<Info>Bla bla</Info>
</exception1>
<exception2 xsi:type="ExceptionAType">
<Type>1</Type>
<Info>Bla bla</Info>
</exception2>
<exception3 xsi:type="ExceptionBType">
<Type>2</Type>
<Info>Bla bla</Info>
</exception3>
</root>
My constraints are:
- I have a hierarchy of ExceptionType
- For all ExceptionAType, <Type> must be "1"
- For all ExceptionBType, <Type> must be "2"
With the following schema, I can validate the xml:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType abstract="true" name="ExceptionType">
<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:complexType name="ExceptionAType">
<xs:complexContent>
<xs:restriction base="ExceptionType">
<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:complexContent> </xs:complexType>
<xs:complexType name="ExceptionBType">
<xs:complexContent>
<xs:restriction base="ExceptionType">
<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:complexContent> </xs:complexType>
<xs:complexType name="RootType">
<xs:sequence>
<xs:element name="exception1" type="ExceptionType"></xs:element> <xs:element name="exception2" type="ExceptionType"></xs:element> <xs:element name="exception3" type="ExceptionType"></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 <Info> in each exception definitions. Is there an other way of doing that, by using extension or other tricks ?
Thanks
Olivier