Jump to content

Populating a DataSet from multiple Xml files


DooVoo

Recommended Posts

The title says it all really. I'm trying to populate a single DataSet with data from multiple xml files, to create either one DataTable for each xml file i read in. Here's the code:

DataSet ds = new DataSet("myds");ds.ReadXml("somefile.xml");ds.ReadXml("somefile2.xml");

Unfortunately this doesn't seem to be working. The first file is read in correctly but the second file doesn't seem to load at all. Does anyone know if this is possible in .NET 1.1? I know that the DataTable type has a ReadXML method in v2 but it's not available in 1.1 :)

Link to comment
Share on other sites

I'm beginning to think posting on this forum is the first step to solving an issue on my own. I can stare at the problem for hours and get no-where, then just by entering the problem here and continuing with my search do i stumble across the information i need. w3schools is now my lucky charm :)So, for those of you who might want to know the answer...When reading in multiple xml files with the same schema (and possible those that can be used to extend the current schema) there is no problem.However, if you are adding multiple xml files with different schemas then you need the DataSet to create a new table for each schema. This is done using one of the overloaded ReadXml(), such as ReadXml(string filename, XmlReadMode mode). By supplying the XmlReadMode you can tell the DataSet what to do when it encounters a schema that doesn't match the first one.To solve my issue I used: DataSet.ReadXml(string filename, XmlReadMode.InferSchema);This causes the DataSet to extend the xml schema in the first table if possible and if not, create a new table with the new schema.Excellent :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...