I using a dataset to read an xml file as shown below DataSet ds = new DataSet(); ds.ReadXml("C:\test.xml");
test.xml contains
<MasterEntities>
<FieldInfo>
<Name>OMID</Name>
<Mandatory>Yes</Mandatory>
<RangeName>AssumptOMID</RangeName>
<DataType>int</DataType>
<Length>10</Length>
</FieldInfo>
<FieldInfo>
<Name>ClientName</Name>
<Mandatory>Yes</Mandatory>
<RangeName>AssumptClient</RangeName>
<DataType>string</DataType>
<Length>50</Length>
</FieldInfo开发者_开发技巧>
<FieldInfo>
<Name>OppName</Name>
<Mandatory>Yes</Mandatory>
<RangeName>AssumptProjectName</RangeName>
<DataType>string</DataType>
<Length>50</Length>
</FieldInfo>
<Settings>
<somesetting1></somesetting1>
<somesetting2></somesetting2>
</Settings>
</MasterEntities>
now i want to read fieldInfo in one dataset/datatable and settings in another dataset/datatable
Please help me with the code
Here's a toy app that does that same thing, and shows the tables in the DataSet in a tree - and the contents of the table in a grid ... handy for seeing what's in a simple XML file ... http://www.dot-dash-dot.com/files/WTFXMLSetup_1_8_0.msi.
Source to the VB.NET project if you want it ... http://www.dot-dash-dot.com/files/wtfxml.zip
Use ReadXml to load your file into a single dataset. Your XML as displayed will read into 2 tables: one called FieldInfo, and the other called Settings.
string fileName = @"C:\Temp\sample.xml";
DataSet ds = new DataSet();
ds.ReadXml(fileName);
To move the second table into a new DataSet, you can do something like this
DataSet ds2 = new DataSet();
ds2.Tables.Add(ds.Tables[1].Copy()); // copy to second dataset
ds.Tables.RemoveAt(1); // remove the original table
精彩评论