views:

81

answers:

1

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.

+1  A: 

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.

Marc Gravell
creating a second model would work, but this is in my actual domain model and is for persistence to an in-house orm so it's a little overkill to create a whole duplicate model. blerg. thanks anyways
Sean Chambers
I guessed as much - and that is fine as long as the mapping is 1:1, but when you start to drift between the two, it is often easier to cut your losses and split the types / responsibility. Otherwise you're going to be fighting it regularly.
Marc Gravell