XML缩进输出,最简单的方法

作者:袖梨 2022-07-02
XML缩进输出,最简单的方法!抛弃孟子E章的XSLT方法吧! ★XML缩进输出,最简单的方法!
By: 无心(cuixiping) 2005-1-28
时不时的有人问xml的缩进。
网上见的多的是孟子E章BLOG上的XSLT方法(他的blog宣传不错,名气大嘛)
网址: http://blog.111com.net/net_lover/archive/2004/07/27/53601.aspx
文章: 利用xslt对xml进行缩进格式化处理
该方法可以解决问题,但是,不仅代码繁琐,而且还需要一个xsl文件。
我觉得是过于麻烦了。
其实一切可以更简单的、更方便的!
问题来源于 MSXML DOM 调用save方法后,有改动的节点将都在一行,
没有回车换行和缩进,阅读很不方便。
你想,微软不会不知道这个问题存在吧,
微软毕竟是微软,他总不会没有替你想个解决办法吧!
都没仔细看微软的文档,就来瞎折腾,把可以简单的搞复杂了!
建议大家如果用微软的 msxml ,就看看他的文档吧。
我现在贴一下我的代码:
★ASP中:
<%
Dim rdr, wrt
set rdr = Server.CreateObject("MSXML2.SAXXMLReader.4.0")
set wrt = Server.CreateObject("MSXML2.MXXMLWriter.4.0")
wrt.indent = True
Set rdr.contentHandler = wrt
'--------------------------------------------
' 可以解析 xml文件、xmlDom对象、xml字符串
' rdr.parseURL ("books.xml");
' rdr.parse (xmlDoc);
' rdr.parse ("
无心(cuixiping)
");
'--------------------------------------------
rdr.parse "
无心(cuixiping)
"
response.write ("")<br />response.write (wrt.output)<br /> </div> </div> </section> <section class="wrap-box"> <div class="g-tit"> <h2>相关文章</h2> </div> <ul class="s-list nobord notop"> <li> <a href="/art-422360.htm" class="s-card"> <div class="s-card-l"> <p class="tit">原神欧洛伦怎么培养 原神欧洛伦培养攻略介绍</p> <div class="info"> <span class="person">游戏攻略</span> <span class="time">2024-11-22</span> </div> </div> <div class="s-card-pic"> <img src="/images/lazy.gif" data-src="/uploads/20241122/logo_674017613ef5b1.jpeg" alt="原神欧洛伦怎么培养 原神欧洛伦培养攻略介绍" /> </div> </a> </li> <li> <a href="/art-422359.htm" class="s-card"> <div class="s-card-l"> <p class="tit">炉石传说跳费大哥德卡组怎么样 炉石传说跳费大哥德卡组推荐介绍</p> <div class="info"> <span class="person">游戏攻略</span> <span class="time">2024-11-22</span> </div> </div> <div class="s-card-pic"> <img src="/images/lazy.gif" data-src="/uploads/20241122/logo_674017607e1e31.jpeg" alt="炉石传说跳费大哥德卡组怎么样 炉石传说跳费大哥德卡组推荐介绍" /> </div> </a> </li> <li> <a href="/art-422358.htm" class="s-card"> <div class="s-card-l"> <p class="tit">蛋仔派对曙光龙女芙瑞怎么样</p> <div class="info"> <span class="person">游戏攻略</span> <span class="time">2024-11-22</span> </div> </div> <div class="s-card-pic"> <img src="/images/lazy.gif" data-src="/uploads/20241122/logo_674010037fb7e1.jpeg" alt="蛋仔派对曙光龙女芙瑞怎么样" /> </div> </a> </li> <li> <a href="/art-422357.htm" class="s-card"> <div class="s-card-l"> <p class="tit">原神恰斯卡怎么养成</p> <div class="info"> <span class="person">游戏攻略</span> <span class="time">2024-11-22</span> </div> </div> <div class="s-card-pic"> <img src="/images/lazy.gif" data-src="/uploads/20241122/logo_6740100266eb11.jpeg" alt="原神恰斯卡怎么养成" /> </div> </a> </li> <li> <a href="/art-422356.htm" class="s-card"> <div class="s-card-l"> <p class="tit">光遇11.22免费魔法有什么</p> <div class="info"> <span class="person">游戏攻略</span> <span class="time">2024-11-22</span> </div> </div> <div class="s-card-pic"> <img src="/images/lazy.gif" data-src="/uploads/20241122/logo_67400ffed50421.jpeg" alt="光遇11.22免费魔法有什么" /> </div> </a> </li> <li> <a href="/art-422355.htm" class="s-card"> <div class="s-card-l"> <p class="tit">光遇11.22大蜡烛在哪里</p> <div class="info"> <span class="person">游戏攻略</span> <span class="time">2024-11-22</span> </div> </div> <div class="s-card-pic"> <img src="/images/lazy.gif" data-src="/uploads/20241122/logo_67400fe6afcc61.jpeg" alt="光遇11.22大蜡烛在哪里" /> </div> </a> </li> </ul> </section> <section class="wrap-box"> <div class="g-tit"> <h2>精彩推荐</h2> </div> <ul class="card-box"> <li class="card3"> <a href="/app/99428.htm" target="_self" class="figure"> <div class="figure-box"> <img src="/images/lazy.gif" data-src="https://img.111cn.net/uploads/20241018/671258fc7c56f.png" alt="沙威玛传奇安卓版" /> </div> <p class="figure-head">沙威玛传奇安卓版</p> <span class="figure-btn">下载</span> </a> </li> <li class="card3"> <a href="/app/99427.htm" target="_self" class="figure"> <div class="figure-box"> <img src="/images/lazy.gif" data-src="https://img.111cn.net/uploads/20241018/6711fc29100e3.png" alt="战盟大乱斗最新版" /> </div> <p class="figure-head">战盟大乱斗最新版</p> <span class="figure-btn">下载</span> </a> </li> <li class="card3"> <a href="/app/99426.htm" target="_self" class="figure"> <div class="figure-box"> <img src="/images/lazy.gif" data-src="https://img.111cn.net/uploads/20241018/6711ef93e4d90.png" alt="大侠立志传最新版" /> </div> <p class="figure-head">大侠立志传最新版</p> <span class="figure-btn">下载</span> </a> </li> <li class="card3"> <a href="/app/99425.htm" target="_self" class="figure"> <div class="figure-box"> <img src="/images/lazy.gif" data-src="https://img.111cn.net/uploads/20241018/6711ca5ba8572.png" alt="苍翼混沌效应最新版" /> </div> <p class="figure-head">苍翼混沌效应最新版</p> <span class="figure-btn">下载</span> </a> </li> </ul> <ul class="card-box-b"> <li class="card10"> <a href="/app/99454.htm" target="_self" class="figure2"> <div class="figure-box"> <img src="/images/lazy.gif" data-src="https://img.111cn.net/uploads/20241019/671393f16002e.jpg" alt="驯龙高手旅程安卓版" /> </div> <div class="figure-cont"> <p class="figure-head">驯龙高手旅程安卓版</p> <div class="figure-desc"> <span>模拟经营</span> <span>驯龙高手旅程安卓版</span> </div> <div class="figure-desc"> <p>一款以奇幻世界为背景的模拟经营游戏</p> </div> </div> <span class="figure-btn">下载</span> </a> </li> <li class="card10"> <a href="/app/99397.htm" target="_self" class="figure2"> <div class="figure-box"> <img src="/images/lazy.gif" data-src="https://img.111cn.net/uploads/20241015/670dc626d93dd.png" alt="全民农场最新版" /> </div> <div class="figure-cont"> <p class="figure-head">全民农场最新版</p> <div class="figure-desc"> <span>模拟经营</span> <span>全民农场最新版</span> </div> <div class="figure-desc"> <p>一款轻松风格的农场经营类型的游戏</p> </div> </div> <span class="figure-btn">下载</span> </a> </li> <li class="card10"> <a href="/app/99010.htm" target="_self" class="figure2"> <div class="figure-box"> <img src="/images/lazy.gif" data-src="https://img.111cn.net/uploads/20240907/logo_66dc0ba5ab7021.jpg" alt="散修功德模拟器完整版" /> </div> <div class="figure-cont"> <p class="figure-head">散修功德模拟器完整版</p> <div class="figure-desc"> <span>模拟经营</span> <span>散修功德模拟器完整版</span> </div> <div class="figure-desc"> <p>散修功德模拟器游戏是一款以功德修炼为题材的模拟游戏</p> </div> </div> <span class="figure-btn">下载</span> </a> </li> <li class="card10"> <a href="/app/99001.htm" target="_self" class="figure2"> <div class="figure-box"> <img src="/images/lazy.gif" data-src="https://img.111cn.net/uploads/20240907/logo_66dc094ae30941.jpg" alt="我的毕业日记无限金币下载" /> </div> <div class="figure-cont"> <p class="figure-head">我的毕业日记无限金币下载</p> <div class="figure-desc"> <span>模拟经营</span> <span>我的毕业日记无限金币下载</span> </div> <div class="figure-desc"> <p>开始毕业后的新生活吧!</p> </div> </div> <span class="figure-btn">下载</span> </a> </li> <li class="card10"> <a href="/app/98996.htm" target="_self" class="figure2"> <div class="figure-box"> <img src="/images/lazy.gif" data-src="https://img.111cn.net/uploads/20240907/logo_66dbd35fadafd1.png" alt="城堡之梦拼图和装饰下载最新版" /> </div> <div class="figure-cont"> <p class="figure-head">城堡之梦拼图和装饰下载最新版</p> <div class="figure-desc"> <span>模拟经营</span> <span>城堡之梦拼图和装饰下载最新版</span> </div> <div class="figure-desc"> <p>城堡之梦拼图和装饰玩家将会在游戏当中感受更多的乐趣体验,你可</p> </div> </div> <span class="figure-btn">下载</span> </a> </li> </ul> </section> <footer class="foot"> <a href="/" class="logo-icon"> <img src="/mobile/images/logo2.png" alt="一聚教程网"> </a> <p>Copyright © 2010-2022</p> <p>111cn.net All Rights Reserved</p> </footer> <script> var advData = {"img_fixed_pc_adv":"https:\/\/img.111cn.net\/uploads\/20240509\/663c2e9729f58.jpg","img_fixed_mob_adv":"https:\/\/img.111cn.net\/uploads\/20240509\/663c2e8793225.jpg","url_adv":"http:\/\/shop.hushen.cn\/shop\/c\/baojianpin.html","str_adv":"\u864e\u795e\u5546\u57ce\uff1a\u5173\u7231\u7537\u6027\uff0c\u66f4\u61c2\u7537\u4eba\u3002\u89e3\u51b3\u5927\u4f17\u7684\u7537\u8a00\u4e4b\u9690","img_popup_adv":"https:\/\/img.111cn.net\/uploads\/20240509\/663c2e748238d.png","pc_show_img":"2","pc_show_popup":"2","pc_show_video":"2","mob_show_img":"2","mob_show_popup":"2","mob_show_video":"2","close_adv":"https:\/\/img.111cn.net\/uploads\/20240508\/663b20650801e.png","video_adv":"\/pc\/images\/pc-adv.mp4"}; </script> <script src="/jspc/funcmob.js" type="text/javascript"></script> <!-- Google tag (gtag.js) --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-DSRRGRV1TL"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-DSRRGRV1TL'); </script> <div class="back-top" style="display: block;"> <span class="icon-box"> <svg class="icon" viewBox="0 0 1024 1024"> <path d="M213.333333 640h170.666667v256h256v-256h170.666667l-298.666667-341.333333zM170.666667 128h682.666666v85.333333H170.666667z" fill="#0374f3"></path> </svg> </span> </div> </div> <script src="/js/stat.js"></script> </body> </html>