I have a lot of XML files and unfortunately no XML schema or any other source of description. So I must generate c# classes based on specific XML file. Problem is that those files have complex structure and they differ between themselves. Is it possible for XmlSerializer to throw exception when it runs into unexpected element?
For example:
[XmlRoot(ElementName = "team"]
public class Team
{
[XmlElement(ElementName = "player"]
public List<Player> Players { get; set; }
[XmlElement(ElementName = "coach"]
public Coach Coach { get; set; }
}
<team>
<player></player>
<player></player>
<coach></coach>
<unexpectedElement></unexpectedElement>
</team>
Element <unexpectedElement>
is not defined in Team class so it should be considered invalid.
Is there any solution to such problem?