首页 新闻 会员 周边

调用接口后,返回数据为xml格式的字符串,如何去解析它。进行数据绑定

0
悬赏园豆:20 [待解决问题]

调用接口后,返回数据为xml格式的字符串,如何去解析它。进行数据绑定

金威的主页 金威 | 初学一级 | 园豆:50
提问于:2011-03-29 17:38
< >
分享
所有回答(3)
-2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
XmlDocument doc
= new XmlDocument();
doc.LoadXml(
"<root>fdsa</root>");
XmlElement root
= doc.DocumentElement;
XmlNodeList xnlist
= root.ChildNodes;//获得根节点下的所有节点

foreach(XmlNode xn in xnlist)
{
//遍历每一个节点
string strText= xn.InnerText;//获得节点的值
string strName = xn.Name;//获得节点的元素名称
//..............................
}
}
}
}
飞云 | 园豆:200 (初学一级) | 2011-03-29 19:13
-1

DataSet ds = new DataSet();
byte[] byteArray = System.Text.Encoding.Unicode.GetBytes("<?xml version='1.0'?><roots><root><id>1</id><name>张三</name></root><root><id>1</id><name>张三</name></root></roots>");
System.IO.MemoryStream stream
= new System.IO.MemoryStream(byteArray);
ds.ReadXml(stream);
DataTable dt
= ds.Tables[0];
测试通过   这个地方 System.Text.Encoding.Unicode 你要注意编码格式

写代码的小2B | 园豆:4371 (老鸟四级) | 2011-03-30 14:02
0

string strText= xn.InnerText;//获得节点的值
string strName = xn.Name;//获得节点的元素名称

这之后,我要怎么绑定到gridview上呢

时光浅巷 | 园豆:202 (菜鸟二级) | 2015-12-08 14:31
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册