FromXml Bug - IgnoreUnknownElements also ignores known elements
Problem reported by Irwin Plitt - November 8 at 9:09 PM
Submitted
FromXml does not work properly when the SerializationContext.IgnoreUnknownElements option is used.

Specifically, when an unknown element is present and it precedes two or more optional elements, the first optional element is also ignored.

The car.xsd is defined as:
<xs:schema>
  <xs:element name="Car">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Make" type="xs:string" />
        <xs:element name="Color" type="xs:string" minOccurs="0" />
        <xs:element name="Owner" type="xs:string" minOccurs="0" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

This is the xml sent to the FromXml method:

 <Car><Make>VW</Make><abc>def</abc><Color>White</Color><Owner>Joe</Owner></Car>

After using the FromXml method and specifying IgnoreUnknownElements=true, and then using the ToXml method, the expected result is:

<Car>
    <Make>VW</Make>
    <Color>White</Color>
    <Owner>Joe</Owner>
</Car>

but the actual xml is missing the Color element, the first optional element following the unknown element:

<Car>
    <Make>VW</Make>
    <Owner>Joe</Owner>
</Car>


1 Reply

Reply to Thread
0
Irwin Plitt Replied
I have a demonstration project that illustrates this issue at github.com/iplitt/liquid-technologies-2019-bug

Reply to Thread