D
Daniel Frey
Hello,
Maybe you know howto. I want to have an element which takes a
subelement. Depending on an attribute within this subelement, a second
subelement may have different attributes allowed:
001 <Service>
002 <Header Kind="1"/>
003 <Input Data="asdasd"/>
004 </Service>
005 <Service>
006 <Header Kind="2"/>
007 <Input User="me" App="main"/>
008 </Service>
How can I specify that in an XML Schema? I tried the following:
001 <xsd:complexType name="service">
002 <xsd:choice minOccurs="1" maxOccurs="1">
003 <xsd:element name="Service" type="kind1"/>
004 <xsd:element name="Service" type="kind2"/>
005 </xsd:choice>
006 </xsd:complexType>
007
008 <xsd:complexType name="kind1">
009 <xsd:sequence>
010 <xsd:element name="Header" type="header1"/>
011 <xsd:element name="Input" type="input1"/>
012 </xsd:sequence>
013 </xsd:complexType>
014
015 <xsd:complexType name="kind2">
016 <xsd:sequence>
017 <xsd:element name="Header" type="header2"/>
018 <xsd:element name="Input" type="input2"/>
019 </xsd:sequence>
020 </xsd:complexType>
021
022 <xsd:complexType name="header1">
023 <xsd:attribute name="Kind" use="required"
type="header1Att"/>
024 </xsd:complexType>
025
026 <xsd:simpleType name="header1Att">
027 <xsd:restriction base="xsd:string">
028 <xsdattern value="1"/>
029 </xsd:restriction>
020 </xsd:simpleType>
031
032 <xsd:complexType name="input1">
033 <xsd:attribute name="Data" use="required"
type="xsd:string"/>
034 </xsd:complexType>
035
036 <xsd:complexType name="header2">
037 <xsd:attribute name="Kind" use="required"
type="header2Att"/>
038 </xsd:complexType>
039
030 <xsd:simpleType name="header2Att">
041 <xsd:restriction base="xsd:string">
042 <xsdattern value="2"/>
043 </xsd:restriction>
044 </xsd:simpleType>
045
046 <xsd:complexType name="input2">
047 <xsd:attribute name="User" use="required"
type="xsd:string"/>
048 <xsd:attribute name="App" use="required"
type="xsd:string"/>
049 </xsd:complexType>
However, doublicate definitions of an element of the same name seem
not to be allowed, which makes sense. But I don't know how to define
this sort of structur e then. Any ideas?
Thanks in advance
Daniel Frey
Maybe you know howto. I want to have an element which takes a
subelement. Depending on an attribute within this subelement, a second
subelement may have different attributes allowed:
001 <Service>
002 <Header Kind="1"/>
003 <Input Data="asdasd"/>
004 </Service>
005 <Service>
006 <Header Kind="2"/>
007 <Input User="me" App="main"/>
008 </Service>
How can I specify that in an XML Schema? I tried the following:
001 <xsd:complexType name="service">
002 <xsd:choice minOccurs="1" maxOccurs="1">
003 <xsd:element name="Service" type="kind1"/>
004 <xsd:element name="Service" type="kind2"/>
005 </xsd:choice>
006 </xsd:complexType>
007
008 <xsd:complexType name="kind1">
009 <xsd:sequence>
010 <xsd:element name="Header" type="header1"/>
011 <xsd:element name="Input" type="input1"/>
012 </xsd:sequence>
013 </xsd:complexType>
014
015 <xsd:complexType name="kind2">
016 <xsd:sequence>
017 <xsd:element name="Header" type="header2"/>
018 <xsd:element name="Input" type="input2"/>
019 </xsd:sequence>
020 </xsd:complexType>
021
022 <xsd:complexType name="header1">
023 <xsd:attribute name="Kind" use="required"
type="header1Att"/>
024 </xsd:complexType>
025
026 <xsd:simpleType name="header1Att">
027 <xsd:restriction base="xsd:string">
028 <xsdattern value="1"/>
029 </xsd:restriction>
020 </xsd:simpleType>
031
032 <xsd:complexType name="input1">
033 <xsd:attribute name="Data" use="required"
type="xsd:string"/>
034 </xsd:complexType>
035
036 <xsd:complexType name="header2">
037 <xsd:attribute name="Kind" use="required"
type="header2Att"/>
038 </xsd:complexType>
039
030 <xsd:simpleType name="header2Att">
041 <xsd:restriction base="xsd:string">
042 <xsdattern value="2"/>
043 </xsd:restriction>
044 </xsd:simpleType>
045
046 <xsd:complexType name="input2">
047 <xsd:attribute name="User" use="required"
type="xsd:string"/>
048 <xsd:attribute name="App" use="required"
type="xsd:string"/>
049 </xsd:complexType>
However, doublicate definitions of an element of the same name seem
not to be allowed, which makes sense. But I don't know how to define
this sort of structur e then. Any ideas?
Thanks in advance
Daniel Frey