62,047
社区成员
发帖
与我相关
我的任务
分享
XmlTextReader reader = new XmlTextReader(Server.MapPath("News.xml"));
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
Response.Write("节点名称:" + reader.LocalName + "<br>");
for (int i = 0; i < reader.AttributeCount; i++)
{
reader.MoveToAttribute(i);
Response.Write("属性:" + reader.Name + "=" + reader.Value + " ");
Response.Write("<br />");
}
break;
}
}
reader.Close();
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(TextBox3.Text);
XmlNode xmlnode1 = xmldoc.SelectSingleNode("xinwen");
foreach (XmlElement xmlnode in xmlnode1.ChildNodes)
{
Response.Write("news_id=" + xmlnode.GetAttribute("news_id"));
Response.Write("news_title=" + xmlnode.GetAttribute("news_title"));
Response.Write("news_author=" + xmlnode.GetAttribute("news_author"));
Response.Write("news_ly=" + xmlnode.GetAttribute("news_ly"));
Response.Write("news_content=" + xmlnode.GetAttribute("news_content"));
Response.Write("news_adddate=" + xmlnode.GetAttribute("news_adddate"));
Response.Write("<br>");
foreach (XmlElement xmlele1 in xmlnode.ChildNodes)
{
Response.Write("a=" + xmlele1.GetAttribute("a"));
Response.Write("b=" + xmlele1.GetAttribute("b"));
Response.Write("e=" + xmlele1.GetAttribute("e"));
Response.Write("f=" + xmlele1.GetAttribute("f"));
}
}
<?xml version="1.0" encoding="gb2312"?>
<xinwen>
<news news_id="5" news_title="XML系统" news_author="邓为" news_ly="原创" news_content="fdgvdf" news_adddate="2008-1-12 15:39:24">
<c a="1" b="2" e="3" f="4"/>
<c a="1" b="2" e="3" f="4"/>
<c a="1" b="2" e="3" f="4"/>
<c a="1" b="2" e="3" f="4"/>
<c a="1" b="2" e="3" f="4"/>
<c a="1" b="2" e="3" f="4"/>
</news>
<news news_id="5" news_title="XML系统" news_author="邓为" news_ly="原创" news_content="fdgvdf" news_adddate="2008-1-12 15:39:24">
<c a="1" b="2" e="3" f="4"/>
<c a="1" b="2" e="3" f="4"/>
<c a="1" b="2" e="3" f="4"/>
<c a="1" b="2" e="3" f="4"/>
<c a="1" b="2" e="3" f="4"/>
<c a="1" b="2" e="3" f="4"/>
</news>
</xinwen>
<?xml version="1.0" encoding="gb2312"?>
<xinwen>
<news news_id="5" news_title="XML系统" news_author="邓为" news_ly="原创" news_content="fdgvdf" news_adddate="2008-1-12 15:39:24">
<c a="1" b="2" e="3" f="4"/>
<c a="1" b="2" e="3" f="4"/>
<c a="1" b="2" e="3" f="4"/>
<c a="1" b="2" e="3" f="4"/>
<c a="1" b="2" e="3" f="4"/>
<c a="1" b="2" e="3" f="4"/>
</news>
<news news_id="5" news_title="XML系统" news_author="邓为" news_ly="原创" news_content="fdgvdf" news_adddate="2008-1-12 15:39:24">
<c a="1" b="2" e="3" f="4"/>
<c a="1" b="2" e="3" f="4"/>
<c a="1" b="2" e="3" f="4"/>
<c a="1" b="2" e="3" f="4"/>
<c a="1" b="2" e="3" f="4"/>
<c a="1" b="2" e="3" f="4"/>
</news>
</xinwen>
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("~/tt.xml"));
string a = "";
for (int i = 0; i < ds.Tables["news"].Rows.Count; i++)
{
for (int j = 0; j < ds.Tables["news"].Columns.Count; j++)
{
a = a + ds.Tables["news"].Rows[i][j].ToString() + ",";
}
if (a.Length > 0) a = a.Substring(0, a.Length - 1);
a = a + "<br />";
}
for (int i = 0; i < ds.Tables["c"].Rows.Count; i++)
{
for (int j = 0; j < ds.Tables["c"].Columns.Count; j++)
{
a = a + ds.Tables["c"].Rows[i][j].ToString() + ",";
}
if (a.Length > 0) a = a.Substring(0, a.Length - 1);
a = a + "<br />";
}
Response.Write(a);