1

Recently i am stuck with a problem during my development.I have some xml values in a variable (not in a seperate file).I transform the xml using xslt and displayed them using xml control in my webpage.NOw my requirement has been changed and I supposed to display the xml values in Gridview instead of xml control.

string getval= //some stuff where webservice returns xml.
// here I specified content to xmldynamic control
xmldynamic.TransformSource=//my xslt comes here..

Now I want to display the transformed XML in gridview.Is it possible...If possible how.. I surfed through net and identified that if xml is in a file, then xml data source can be used,transformed and define datasource to gridview.But in my case its in a variable.

Sasidharan
  • 3,676
  • 3
  • 19
  • 37
  • 1
    Take a look at the documentation for XMLDataSource at http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.xmldatasource(v=vs.110).aspx. That has a 'Data' property which could be used into of the 'DataFile' property. – Tim C Mar 11 '14 at 10:02

2 Answers2

1

There a lot of 3rd party Class / Software that does that.

For example for web an this is a powerfull app maybe you dont want this extensive app on your side but consider ExtJS

http://docs.sencha.com/extjs/4.2.2/

///

Also check this old topic for more

Is there an XML Editor with grid view similar to that of XMLSpy?

Community
  • 1
  • 1
Luis Lopes
  • 506
  • 4
  • 14
1

Try below steps:

1.) Load the XML data in a StringReader

2.) feed this StringReader object to ReadXml() method of DataSet

3.) Now bind this DataSet to your GridView. This step is always tricky ( May be) as depending on the XML format Many times I needed to modify it slightly as : ds.Tables[0]; or ds.Tables[1]; etc...

Sample:

string xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<Cameras>
  <Camera>
    <Model>Canon EOS-1D</Model>
    <Price>$5219</Price>
  </Camera>
  <Camera>
    <Model>Canon EOS-1D Mark IV</Model>
    <Price>$5000</Price>
  </Camera>
</Cameras>";

StringReader sr = new StringReader(xml); // Step 1
DataSet ds = new DataSet();
ds.ReadXml(sr); // Step 2
GridView1.DataSource = ds.Tables[0]; // Step 3
GridView1.DataBind();
R.C
  • 10,417
  • 2
  • 35
  • 48
  • So after transformation, are you getting a final XML ? – R.C Mar 11 '14 at 11:37
  • Flopscientist.....as u see in my code above I received xml and transformed in the earlier steps itself..now I want to make that xml data as dataset which ll make me to pass the same as datasource to grid... – Sasidharan Mar 13 '14 at 14:02
  • 1
    Yes if after transforming/modifications u get your final XML, then pass this xml to StringReader in Step 1 – R.C Mar 14 '14 at 03:39