xsd - XML Elements in Any Order, Some Required and Others Aren't -
i'm trying have list of elements allowed in order. of elements required (min of 1, max of 1), optional maximum of 1 , optional number. have , xsd valid, when go validate xml, rules i'm trying implement aren't enforced. example, id not made required.
<xsd:complextype name="feedtype"> <xsd:annotation> <xsd:documentation> atom feed construct defined in section 4.1.1 of format spec. </xsd:documentation> </xsd:annotation> <xsd:choice minoccurs="3" maxoccurs="unbounded"> <xsd:element name="author" type="atom:persontype" minoccurs="0" maxoccurs="unbounded"/> <xsd:element name="category" type="atom:categorytype" minoccurs="0" maxoccurs="unbounded"/> <xsd:element name="contributor" type="atom:persontype" minoccurs="0" maxoccurs="unbounded"/> <xsd:element name="generator" type="atom:generatortype" minoccurs="0" maxoccurs="1"/> <xsd:element name="icon" type="atom:icontype" minoccurs="0" maxoccurs="1"/> <xsd:element name="id" type="atom:idtype" minoccurs="1" maxoccurs="1"/> <xsd:element name="link" type="atom:linktype" minoccurs="0" maxoccurs="unbounded"/> <xsd:element name="logo" type="atom:logotype" minoccurs="0" maxoccurs="1"/> <xsd:element name="rights" type="atom:texttype" minoccurs="0" maxoccurs="1"/> <xsd:element name="subtitle" type="atom:texttype" minoccurs="0" maxoccurs="1"/> <xsd:element name="title" type="atom:texttype" minoccurs="1" maxoccurs="1"/> <xsd:element name="updated" type="atom:datetimetype" minoccurs="1" maxoccurs="1"/> <xsd:element name="entry" type="atom:entrytype" minoccurs="0" maxoccurs="unbounded"/> <xsd:any namespace="##other" minoccurs="0" maxoccurs="unbounded"/> </xsd:choice> <xsd:attributegroup ref="atom:commonattributes"/> </xsd:complextype>
choice allows 1 of child elements present in xml graph. looks want use sequence if elements in same order. if order variable should use all , wrap elements have maxoccurs="unbounded" in containing list element, because all allows 1 or 0 occurrences of child elements.
edit:
and should remove minoccurs & maxoccurs choice element. allows enforce 3 choices, doesn't allow specify choices (including repeating same element multiple times). don't know you're trying enforce, won't enforced way.
edit 2:
you can create list wrappers follows (using link element example):
<xs:element name="linklist" minoccurs="0" maxoccurs="1"> <xs:complextype> <xs:sequence> <xs:element name="link" type="atom:linktype" minoccurs="0" maxoccurs="unbounded" /> </xs:sequence> </xs:complextype> </xs:element> and in xml document (for example) nest link elements in linklist:
old:
<other elements...> <id>...</id> <link>...</link> <link>...</link> <logo>...</logo> <other elements...> new:
<other elements...> <id>...</id> <linklist> <link>...</link> <link>...</link> </linklist> <logo>...</logo> <other elements...>
Comments
Post a Comment