loading XML into a dataset

M

Mike P

I'm currently reading data from an XML file using XPathNavigator and
XPathNodeIterator to select the subset of data that I want. I've never
using the XPath objects before so I'm not sure how to get this data into
a dataset.

XPathDocument doc = new
XPathDocument(@"C:\inetpub\wwwroot\test\test.xml");
XPathNavigator nav = doc.CreateNavigator();
XPathNodeIterator iter =
nav.Select("/test/translation/engword[preceding-sibling::fraword = '" +
strFraWord + "']");

Can anybody help me out with this? Any assistance would be really
appreciated.


Cheers,

Mike
 
M

mblamire

Hi Mike,

Check this out...

This example uses XmlDataDocument to load the XML and then accessing the
data using dataset...

<http://samples.gotdotnet.com/quickstart/howto/doc/Xml/LoadDataSetXMLData.aspx>

Another alternative is using ReadXml method of the Dataset...

<http://msdn.microsoft.com/library/d...s/cpguide/html/cpconloadingdatasetfromxml.asp>

Hope this helps...

Cheers,
Madhu



Mike P said:
I'm currently reading data from an XML file using XPathNavigator and
XPathNodeIterator to select the subset of data that I want. I've never
using the XPath objects before so I'm not sure how to get this data into
a dataset.

XPathDocument doc = new
XPathDocument(@"C:\inetpub\wwwroot\test\test.xml");
XPathNavigator nav = doc.CreateNavigator();
XPathNodeIterator iter =
nav.Select("/test/translation/engword[preceding-sibling::fraword = '" +
strFraWord + "']");

Can anybody help me out with this? Any assistance would be really
appreciated.


Cheers,

Mike


to extend the words of Madhu here is a snippet from an application of mine
which should help you, the second function is the one you should
concentrate on... this one is for ultimately populating a datagrid.


DataSet ds = ImportDataGrid.ImportSavedData();
if (ds != null) {
this.computerGrid.DataSource = ds;
} else {
this.updateMessageBox("There was a problem importing the data, the file
may not exist or there is a sytax error with the import file
(xml\\datagrid.xml)");
}


//ImportDataGrid.ImportSaveData()
public static DataSet ImportSavedData() {
DataSet ds = null;
try {
ds = new DataSet();
//this returns a (string)fileName located in the properties XML file.
ds.ReadXml(Properties.getString("data.location"));
} catch {
MessageBox.Show("The data file was not found, or it couldn't be
imported.", "File Not Found", MessageBoxButtons.OK,
MessageBoxIcon.Information);
} finally {
return ds;
}
}

HTH
Mike
http://www.blamires.co.uk/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top