string strxml = "121122111222";
DataSet ds = new DataSet();
Stream stream = new MemoryStream(Encoding.Default.GetBytes(strxml));
ds.ReadXml(stream);
GridView1.DataSource = ds;
GridView1.DataBind();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataSet ds = new DataSet();
TextReader reader = new StringReader(@"
The Chi-lites
Soul
A lonely man
1972
Babyface
R&B
unknown
Babyface
R&B
The essential babyface
2001
Babyface
R&B
Grown and sexy
2005
Maria Arredondo
Pop
Not going under
2004
Leona Lewis
Pop
Unknown
2008
Usher
R&B
Usher
2008
Christina Aguilera
Blues
Back to basics
2004
Sting
Pop
Shape of my heart
");
//读取Xml字符串 用来接收WebService返回数据
ds.ReadXml(reader, XmlReadMode.Auto);
//生成Xml文件
//ds.WriteXml(Server.MapPath("xml/song_bak.xml"));
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
#region 接口返回的Xml转换成DataSet
///
/// 返回的Xml转换成DataSet
///
/// Xml字符
///
private DataSet GetDataSet(string text)
{
try
{
XmlTextReader reader = new XmlTextReader(new StringReader(text));
reader.WhitespaceHandling = WhitespaceHandling.None;
DataSet ds = new DataSet();
ds.ReadXml(reader);
reader.Close();
ds.Dispose();
return ds;
}
catch
{
return null;
}
}
#endregion
#region 后台提交数据且获取接口返回的数据
///
/// 后台提交数据且获取接口返回的数据
///
/// 地址
///
public static string GetRequestString(string relativePath)
{
string requestUrl = relativePath;
try
{
// 创建一个HTTP请求
HttpWebRequest request = (System.Net.HttpWebRequest)WebRequest.Create(requestUrl);
request.Method = "GET";
StreamReader jsonStream = new StreamReader(request.GetResponse().GetResponseStream());
string jsonObject = jsonStream.ReadToEnd();
return jsonObject;
}
catch
{
return string.Empty;
}
}
#endregion