XDocument.Validate(...) - Ignore Extra Elements

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p style="margin:0cm 0cm 10pt <span style="font-family:Calibri; font-size:small Hi,
<p style="margin:0cm 0cm 10pt <span style="font-family:Calibri; font-size:small I have an XSD file below.
<p style="margin:0cm 0cm 10pt <span style="color:#c00000 <span style="font-size:small <span style="font-family:Calibri <xsd:schema xmlns:xsd=http://www.w3.org/2001/XMLSchema><br/>
<xsd:element name=Root><br/>
<xsd:complexType><br/>
<xsd:sequence><br/>
<xsd:element name=Child1 minOccurs=1 maxOccurs=1/><br/>
<xsd:element name=Child2 minOccurs=1 maxOccurs=1/><br/>
</xsd:sequence><br/>
</xsd:complexType><br/>
</xsd:element><br/>
</xsd:schema>
<p style="margin:0cm 0cm 10pt <span style="font-family:Calibri; font-size:small When I use the extension method XDocument.Validate(...) to validate the XML below. I get a "The element Root has invalid child element Child3." error.
<p style="margin:0cm 0cm 10pt <span style="color:#c00000 <span style="font-size:small <span style="font-family:Calibri <Root><Child1/><Child2/><Child3/></Root>
<p style="margin:0cm 0cm 10pt <span style="font-family:Calibri; font-size:small Is it possible to setup the validation so that it only checks for Child1 and Child2, and ignores any extra elements (e.g. Child3).
<p style="margin:0cm 0cm 10pt <span style="font-family:Calibri; font-size:small Thanks,<br/>
Ben.

View the full article
 
Back
Top