开发者

XmlDocument.Validate ignore properties without [XmlIgnore]

开发者 https://www.devze.com 2022-12-12 12:55 出处:网络
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

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 c开发者_开发知识库onvention rather then explicitly add attributes all throughout my object model.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消