[Xml-compile] Required child of optional parent.

Nicholas Ellis nicholas.ellis at leadkarma.com
Mon Jun 3 15:44:49 GMT 2013


I have an xsd and am trying to validate my xml generated against it.
 However I have run into a strange problem with parent child elements and
whether they are required or not.  So if I have an xsd that looks something
like this:

<xsd:element ref=3D"Parent" minOccurs=3D"0">
<xsd:element name=3D"Parent" type=3D"Parent_Type"/>


<xsd:complexType name=3D"Parent_Type">
<xsd:sequence>
  <xsd:element ref=3D"Child" minOccurs=3D"1" maxOccurs=3D"1"/>
</xsd:sequence>
</xsd:complexType>

When I try to compile my xml without Parent it complains that Child is
required, but when I took the same xml to an online validator against the
xsd it passed.

Which one is right?  If a Child element is required and a Parent is not
should it throw an error if the Child is not present, or should it only be
a problem if the Parent exists and lacks the Child?



Cheers,
Nicholas Ellis
Jr. Software Engineer
LeadKarma LLC
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/xml-compile/attachments/20130603/49=
1b6288/attachment.htm


More information about the Xml-compile mailing list