楼主参考一下
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("data.xml"));
StringBuilder content = new StringBuilder();
XmlNodeList nodeLst = doc.GetElementsByTagName("movie");
foreach (XmlNode node in nodeLst)
{
content.Append("元素名:" + node.Name + "\r\n");
for (int i = 0; i < node.Attributes.Count; i++)
{
content.Append("属性名" + node.Attributes[i].Name + ":" + node.Attributes[i].Value + "\r\n");
}
foreach (XmlNode childNode in node.ChildNodes)
{
content.Append("子元素名" + childNode.Name + ":"+childNode.FirstChild.Value+"\r\n");
}
}
TextBox1.Text = content.ToString();
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("data.xml"));
StringBuilder content = new StringBuilder();
XmlNodeList nodeLst = doc.GetElementsByTagName("movie");
foreach (XmlNode node in nodeLst)
{
content.Append("元素名:" + node.Name + "\r\n");
for (int i = 0; i < node.Attributes.Count; i++)
{
content.Append("属性名" + node.Attributes[i].Name + ":" + node.Attributes[i].Value + "\r\n");
}
foreach (XmlNode childNode in node.ChildNodes)
{
content.Append("子元素名" + childNode.Name + ":"+childNode.FirstChild.Value+"\r\n");
}
}
TextBox1.Text = content.ToString();
解决方案 »
- !!!!!!!!!!!!!!!!!!!!!!!!!!!奇怪 session 跳转页面丢失 技术问题 !!!!!!!!!!!!!!!!!!!!!!!
- 关于findcontrol
- ASP .Net构建网站,同时要考虑将来移动终端通过APP访问网站,该怎么办?
- 编程实现局部更新的问题
- AdRotator控件能不能不刷新就循环显示图片呢,为什么只有刷新的时候才会更换图片呢?
- 如何在web页面弹出类似操作系统中的对话框
- 利用javascript中的window.open打开pdf的问题。急!急!急!急!
- datagrid 的itemcommand和自动分页是不是不能共存?
- treeview 问题????????急急急急急!!!!!!!
- 帮帮忙啊!!!
- 怎么将textbox中用逗号隔开的数据分为一列的不同字段啊
- 关于ASP.NET引用DLL报错,帮忙看看是哪出了问题?谢谢
private void test()
{
XmlDocument xd = new XmlDocument();
xd.Load("e:/test.xml"); //load all movies
XmlNodeList xnl = xd.SelectNodes("//movie");
foreach(XmlNode xn in xnl)
{
//load all attributes of current movie
foreach (XmlAttribute xa in xn.Attributes)
{
Response.Write("<b>" + xa.Name + "</b>:" + xa.InnerText + ",");
}
Response.Write ("<hr size=\"1\" />"); //the child nodes of current node which named movie
foreach (XmlNode xcn in xn.ChildNodes)
{
Response.Write("<b>" +xcn.Name + "</b>:" + xcn.InnerText + "<br/>"); if (xcn.HasChildNodes)
{
Response.Write("<br/>------------------------<br/>");
} //load nodes named file
foreach (XmlNode xccn in xcn.ChildNodes)
{
Response.Write("<b>" + xccn.Name + "</b>:" + xccn.InnerText + "<br/>");
}
}
Response.Write("<br/><br/><br/>");
}
}
}