Transform an XML to HTML - StringReader
Here is a great way to transform an XML string returned from DB Query to a HTML using DataGrid/List...
The xml represent by the StringReader, witch implements a TextReader that reads from a string.
Then loaded to DataSet (by ds.ReadXML), and finally binds to the DataGrid.
//Supposed this is the text returning from DB...
string xml = "<rows><row id='1'><name>Gilad</name><address>Burla</address>"
+ "<country>Israel</country></row><row id='2'><name>John</name>"
+ "<address>Igaal Alon</address><country>Israel</country></row></rows>";
using (StringReader reader = new StringReader(xml))
{
DataSet ds = new DataSet();
ds.ReadXml(reader);
dgTest.DataSource = ds;
dgTest.DataBind();
} |