您的位置:首页 > 其它

如何格式化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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: