1个回答
展开全部
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Text;
// 运用xmlReader解析文件
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
StringBuilder s = new StringBuilder("");
XmlReader read = new XmlTextReader(Server.MapPath("App_Data/servlet.xml"));
try{
// 开始读取文件
while (read.Read()) {
switch (read.NodeType) {
case XmlNodeType.XmlDeclaration: // 如果是文档声明
s.Append("<?"+read.Value + "?>\n");
break;
case XmlNodeType.Element: // 如果是元素开始
s.Append("<").Append(read.Name);
for (int i = 0; i < read.AttributeCount; i++) {
read.MoveToAttribute(i);
s.Append(" ").Append(read.Name).Append("=").Append(read.GetAttribute(i));
}
s.Append(">\n");
break;
case XmlNodeType.EndElement: // 如果是元素结束
s.Append("</").Append(read.Name).Append(">\n");
break;
case XmlNodeType.Text:
s.Append(read.Value+"\n");
break;
}
}
}catch(Exception ee){
ee.ToString();
}finally{
read.Close();
}
TextBox1.Text = s.ToString();
}
}
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Text;
// 运用xmlReader解析文件
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
StringBuilder s = new StringBuilder("");
XmlReader read = new XmlTextReader(Server.MapPath("App_Data/servlet.xml"));
try{
// 开始读取文件
while (read.Read()) {
switch (read.NodeType) {
case XmlNodeType.XmlDeclaration: // 如果是文档声明
s.Append("<?"+read.Value + "?>\n");
break;
case XmlNodeType.Element: // 如果是元素开始
s.Append("<").Append(read.Name);
for (int i = 0; i < read.AttributeCount; i++) {
read.MoveToAttribute(i);
s.Append(" ").Append(read.Name).Append("=").Append(read.GetAttribute(i));
}
s.Append(">\n");
break;
case XmlNodeType.EndElement: // 如果是元素结束
s.Append("</").Append(read.Name).Append(">\n");
break;
case XmlNodeType.Text:
s.Append(read.Value+"\n");
break;
}
}
}catch(Exception ee){
ee.ToString();
}finally{
read.Close();
}
TextBox1.Text = s.ToString();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询