开发者

Load XML file into object. Best method?

开发者 https://www.devze.com 2022-12-26 05:17 出处:网络
We are receiving an XML file from our client. I want to load the开发者_Python百科 data from this file into a class, but am unsure about which way to go about it.

We are receiving an XML file from our client. I want to load the开发者_Python百科 data from this file into a class, but am unsure about which way to go about it.

I have an XSD to defining what is expected in the XML file, so therefore i can easily validate the XML file.

Can i use the XSD file to load the data into a POCO, using some sort of serialization?

The other way i was thinking was to load the xml into a XMLDocument and use XPath to populate each property in my class.

Cheers for any advice


Depending on how complex the XSD is, you have a couple of options:

  • Use xsd.exe to generate C# classes which can be used in conjunction with the XmlSerializer.
  • Use svcutil.exe with the /dconly argument to generate DataContract-attributed types appropriate for use with the DataContractSerializer.
0

精彩评论

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