Load XML file into object. Best method?
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.
精彩评论