XmlSerializer.Deserialize - ignore unnecessary elements?

I have an XSD schema in which I created a class to use xsd.exe, and I'm trying to use XmlSerializer.Deserializeto create an instance of this class from an XML file that must match the XSD schema. Unfortunately, there are several additional elements in the XML file that are not expected in the schema, which causes a reset System.InvalidOperationExceptionfrom Deserialize.

I tried adding elements to my schema <xs:any>, but that doesn't seem to make any difference.

My question is: is there a way to get XmlSerializer.Deserializeto ignore these extra elements?

+3
source share
2 answers

, . , , xsd.exe, XML. XML- + Visual Studio XML- XML-.

+2

, , :

[XmlAnyAttribute]
public XmlAttribute[] AnyAttributes;

[XmlAnyElement]
public XmlElement[] AnyElements;

, . , - , .

, DasBlog.

+5

Source: https://habr.com/ru/post/1758527/


All Articles