I have an XML file and I want to retrieve data from it so I can store this data in my database. I’ve searched and I found this post.
I don’t know what the following means:
Create a XML schema so you can deserialize this XML into a .NET object – works best if you have tons of those files to import.
So:
- I’d like to see some articles or examples of how to do this.
- How do I check data that comes from an XML file?
This means that you can write a .NET object that reflects the structure of your XML file and then deserialize the XML file back to an instance of this object. For example if you have the following XML:
you could have a User class:
and then deserialize:
You can apply attributes to the .NET object in order to control the serialization/deserialization process.
As far as the validation of the XML file is concerned you could write a XSD schema (which is a XML file) representing the data structure of your file and then validate it against this schema. This will ensure that the XML file you have as an input obeys the defined rules (it has the correct node names, required properties, …).