C# – XmlDocument.Validate ignore properties without [XmlIgnore]


I have a object that has a number of properties that aren't present in the xsd file. When doing XmlDocument.Validate is there a way I can tell it to ignore properties that are not present in the xsd and instead just ensure that the properties required by xsd are present in the xml document?

I can get around this by adding [XmlIgnore] attributes all over my class but I would rather accomplish this by convention rather then explicitly add attributes all throughout my object model.

Best Solution

I doubt there is. Personally I would create a separate DTO, as it sounds like you're trying to make one object serve two jobs. Another option would be to use the XmlSerializer ctor that allows you to specify attribs at runtime, but this is much more work than [XmlIgnore].

So if you just want it to work: [XmlIgnore]. If you want it to be "pure", create a second DTO model and translate between them.