如何格式化web.config
2010-10-18 17:06
218 查看
private void FormatXml(string sUnformattedXml)
{
//load unformatted xml into a dom
XmlDocument xd = new XmlDocument();
xd.Load(Server.MapPath(sUnformattedXml));
//will hold formatted xml
StringBuilder sb = new StringBuilder();
//pumps the formatted xml into the StringBuilder above
StringWriter sw = new StringWriter(sb);
//does the formatting
XmlTextWriter xtw = null;
try
{
//point the xtw at the StringWriter
xtw = new XmlTextWriter(sw);
//we want the output formatted
xtw.Formatting = Formatting.Indented;
//get the dom to dump its contents into the xtw
xd.WriteTo(xtw);
}
finally
{
//clean up even if error
if (xtw != null)
xtw.Close();
}
xd.Save(Server.MapPath("~/TestXMLFormat/aa_new.config"));
}
参考帖子:
http://www.codeproject.com/KB/cpp/FormattingXML.aspx
http://blog.csdn.net/wisdom521/archive/2007/11/29/1907261.aspx
{
//load unformatted xml into a dom
XmlDocument xd = new XmlDocument();
xd.Load(Server.MapPath(sUnformattedXml));
//will hold formatted xml
StringBuilder sb = new StringBuilder();
//pumps the formatted xml into the StringBuilder above
StringWriter sw = new StringWriter(sb);
//does the formatting
XmlTextWriter xtw = null;
try
{
//point the xtw at the StringWriter
xtw = new XmlTextWriter(sw);
//we want the output formatted
xtw.Formatting = Formatting.Indented;
//get the dom to dump its contents into the xtw
xd.WriteTo(xtw);
}
finally
{
//clean up even if error
if (xtw != null)
xtw.Close();
}
xd.Save(Server.MapPath("~/TestXMLFormat/aa_new.config"));
}
参考帖子:
http://www.codeproject.com/KB/cpp/FormattingXML.aspx
http://blog.csdn.net/wisdom521/archive/2007/11/29/1907261.aspx
相关文章推荐
- 如何:从Web.config 文件读取连接字符串
- SQL Server数据库连接 Web.config如何配置
- 如何在web.config中建立公用的的数据库连接
- 如何让虚拟目录里面的webconfig不继承网站的设置
- 在webconfig中写好连接后,在程序中如何调用?
- 如何用代码方式获取Web.config中system.serviceModel/client节点的address
- 如何让虚拟目录里面的webconfig不继承网站的设置
- 如何动态设置全局theme,及在web.config中读取pages节点的内容。
- 一个站点存在多个web.config时如何管理
- 如何使用web.config里的sectiongroup
- 如何在web.config中存储自定义对象
- 多个web.config如何管理
- 如何在ASP.NET的web.config配置文件中添加MIME类型
- C#中如何读取webconfig.xml里的数据库连接字符串
- 技巧和诀窍:如何在Web.config中注册用户控件和自定义控件
- 在web.config中如何配置数据库连接字符串,较为安全?
- 如何配置Web.config文件 for ASP.NET
- Asp.Net 2.0连接ACCESS数据库相对路径问题,web.config中如何使用相对路径
- AppDomain以及如何改变web.config / App.config位置
- webconfig和appconfig中出现特殊字符如何处理