62,054
社区成员
发帖
与我相关
我的任务
分享
//清洗
XmlDocument doc = new XmlDocument();
doc.LoadXml(s);
XmlNodeList nodes= doc.SelectNodes("table/tr");
foreach (XmlElement node in nodes)
{
node.Attributes.RemoveAll(); //这里把Tr所有的属性都去掉
for (int i = 0; i < node.ChildNodes.Count; i++) //列的循环,为每个列指定名称
{
....
}
}
string s = "<table><tr><td>aaaa</td><td>bbbb</td></tr><tr><td>rrrr</td><td>uuuu</td></tr></table>";
s = "<?xml version=\"1.0\" standalone=\"yes\"?>" + s;
//清洗
XmlDocument doc = new XmlDocument();
doc.LoadXml(s);
XmlNodeList nodes= doc.SelectNodes("table/tr");
foreach (XmlElement node in nodes)
{
for (int i = 0; i < node.ChildNodes.Count; i++) //列的循环,为每个列指定名称
{
XmlNode n = doc.CreateNode(XmlNodeType.Element,"col" + i.ToString(),"");
n.InnerXml = node.ChildNodes[i].InnerXml;
node.ReplaceChild(n, node.ChildNodes[i]);
}
}
//导入Dataset
StringReader tr = new StringReader(doc.InnerXml);
DataSet ds = new DataSet();
ds.ReadXml(tr);
//显示
gvlist.DataSource = ds.Tables[0];
gvlist.DataBind();
<table id="dgItemList" runat="server">
tb.Controls //获得信息