Ensure child element cannot exist without parent Using Xsd -
i facing issues in trying schema validation inside xsd.
valid case
<root> <groups> <group/> </groups> </root> valid case <root> <groups/> </root> invalid case
<root> <group/> </root> how ensure particular child element can exist under parent, not alone in xml through xsd?
in e.g. group cannot exist alone, can exist when groups parent...
someone replied not make group element global i.e contain within groups element...
but there can case, group not direct child of parent. e.g valid case
<groups> <class> <group> </class> </groups> what should done in cases...as class needs refer group too...
based on question, sounds me more want class , group interchangeable. that, want use recursive schema element, so...
<xsd:element name="groups"> <xsd:complextype> <xsd:complexcontent> <xsd:extension base="branchtype"/> </xsd:complexcontent> </xsd:complextype> </xsd:element> <xsd:complextype name="branchtype"> <xsd:sequence> <xsd:choice minoccurs="0" maxoccurs="unbounded"> <xsd:element name="class" type="branchtype" minoccurs="0" maxoccurs="1"/> <xsd:element name="group" minoccurs="0" maxoccurs="1"/> </xsd:choice> </xsd:sequence> </xsd:complextype> we define branchtype can contain mix of group elements or (via class element). define top level groups type branchtype. use sequence of choice class , group elements can appear in order, number of times, level of nesting.
Comments
Post a Comment