From here to there: XmlDocument to a DataSet

M

michael sorens

I want to populate a DataGridView from an XML data set, but from an
XmlDocument rather than from a file:

XmlDocument doc = new XmlDocument();
// populate 'doc' here...

DataSet ds = new DataSet();

// what do I use here?
//ds.ReadXml("file.xml");

dataGridView.DataSource = ds;

There is no DataSet.ReadXml that takes an XmlDocument, and I cannot seem
to see a clear path between Streams, XmlReaders, TextReaders, etc. to
navigate from the XmlDocument to the DataSet. Suggestions?
 
G

Guest

You just have to massage it into a format that it is happy with. Here is one
way:

XmlDocument doc = new XmlDocument();
doc.LoadXml("<root><table><line>hwooo</line></table></root>");
MemoryStream ms = new MemoryStream();
doc.Save(ms);
ms.Seek(0,0);
DataSet Ds = new DataSet();
Ds.ReadXml(ms,XmlReadMode.Auto);
string x=(string)Ds.Tables[0].Rows[0][0];
 

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