How to get XML Document from String

Hi friends

Here i am going to show you how to get XML data in the form of Text or String into the data source .
if we have a string data having a XML data like this,

string sXmlString="<parameters><Parameter><Name>Name</Name><Value>Rajesh</Value></Parameter><Parameter><Name>City</Name><Value>Jaipur</Value></Parameter><Parameter><Name>Phone No</Name><Value>12345678</Value></Parameter><Parameter><Name>State</Name><Value>Rajasthan</Value></Parameter><Parameter><Name>Pin</Name><Value>302020</Value></Parameter><Parameter><Name>Country</Name><Value>India</Value></Parameter></parameters>";

       XDocument doc = XDocument.Parse(sXmlString);
        XElement root = doc.Root;
        DataSet dataSet = new DataSet();
        dataSet.ReadXml(new StringReader(doc.ToString()));
        GridView1.DataSource = dataSet.Tables[0];
        GridView1.DataBind();
 //Here Parse Method use to Parse the string type of data to the Xml document type.

The Grid will show data like this



1 comment:

  1. Nice Post !


    Pooja

    MLM Developers India

    http://mlmdevelopers.com/products/mlm-software/corporate-mlm-soft/feature.html

    ReplyDelete