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-424487.htm" class="s-card"> <div class="s-card-l"> <p class="tit">光遇12.26每日任务怎么做 光遇12月26日每日任务做法攻略</p> <div class="info"> <span class="person">游戏攻略</span> <span class="time">2024-12-26</span> </div> </div> <div class="s-card-pic"> <img src="/images/lazy.gif" data-src="/uploads/20241226/logo_676cce83dcf8a1.jpeg" alt="光遇12.26每日任务怎么做 光遇12月26日每日任务做法攻略" /> </div> </a> </li> <li> <a href="/art-424486.htm" class="s-card"> <div class="s-card-l"> <p class="tit">光遇12.26季节蜡烛在哪里 光遇12月26日季节蜡烛位置攻略</p> <div class="info"> <span class="person">游戏攻略</span> <span class="time">2024-12-26</span> </div> </div> <div class="s-card-pic"> <img src="/images/lazy.gif" data-src="/uploads/20241226/logo_676cce82d6a891.jpeg" alt="光遇12.26季节蜡烛在哪里 光遇12月26日季节蜡烛位置攻略" /> </div> </a> </li> <li> <a href="/art-424484.htm" class="s-card"> <div class="s-card-l"> <p class="tit">光遇12.26复刻先祖在哪里 12月26日扫把头先祖复刻位置介绍</p> <div class="info"> <span class="person">游戏攻略</span> <span class="time">2024-12-26</span> </div> </div> <div class="s-card-pic"> <img src="/images/lazy.gif" data-src="/uploads/20241226/logo_676cce814774f1.jpeg" alt="光遇12.26复刻先祖在哪里 12月26日扫把头先祖复刻位置介绍" /> </div> </a> </li> <li> <a href="/art-424485.htm" class="s-card"> <div class="s-card-l"> <p class="tit">光遇12.26复刻先祖是谁 光遇12月26日扫把头先祖复刻介绍</p> <div class="info"> <span class="person">游戏攻略</span> <span class="time">2024-12-26</span> </div> </div> <div class="s-card-pic"> <img src="/images/lazy.gif" data-src="/uploads/20241226/logo_676cce8245f8e1.jpeg" alt="光遇12.26复刻先祖是谁 光遇12月26日扫把头先祖复刻介绍" /> </div> </a> </li> <li> <a href="/art-424483.htm" class="s-card"> <div class="s-card-l"> <p class="tit">光遇12.26雪花代币在哪里 光遇12月26日宴会节代币收集攻略</p> <div class="info"> <span class="person">游戏攻略</span> <span class="time">2024-12-26</span> </div> </div> <div class="s-card-pic"> <img src="/images/lazy.gif" data-src="/uploads/20241226/logo_676cce7d938901.jpeg" alt="光遇12.26雪花代币在哪里 光遇12月26日宴会节代币收集攻略" /> </div> </a> </li> <li> <a href="/art-424482.htm" class="s-card"> <div class="s-card-l"> <p class="tit">光遇12.26免费魔法有什么 光遇12月26日免费魔法收集攻略</p> <div class="info"> <span class="person">游戏攻略</span> <span class="time">2024-12-26</span> </div> </div> <div class="s-card-pic"> <img src="/images/lazy.gif" data-src="/uploads/20241226/logo_676cce7be88611.jpeg" alt="光遇12.26免费魔法有什么 光遇12月26日免费魔法收集攻略" /> </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/101544.htm" target="_self" class="figure"> <div class="figure-box"> <img src="/images/lazy.gif" data-src="https://img.111cn.net/uploads/20241226/logo_676cb092a2bd71.png" alt="恐龙生存侏罗纪世界 安卓版v0.0.32" /> </div> <p class="figure-head">恐龙生存侏罗纪世界 安卓版v0.0.32</p> <span class="figure-btn">下载</span> </a> </li> <li class="card3"> <a href="/app/101536.htm" target="_self" class="figure"> <div class="figure-box"> <img src="/images/lazy.gif" data-src="https://img.111cn.net/uploads/20241226/logo_676cb0896d6171.png" alt="死神vs火影沃特水改版全人物 安卓版vwts_1.3.60" /> </div> <p class="figure-head">死神vs火影沃特水改版全人物 安卓版vwts_1.3.60</p> <span class="figure-btn">下载</span> </a> </li> <li class="card3"> <a href="/app/101529.htm" target="_self" class="figure"> <div class="figure-box"> <img src="/images/lazy.gif" data-src="https://img.111cn.net/uploads/20241226/logo_676cb077371b81.png" alt="小猫传奇免广告版 最新版本v64" /> </div> <p class="figure-head">小猫传奇免广告版 最新版本v64</p> <span class="figure-btn">下载</span> </a> </li> <li class="card3"> <a href="/app/101528.htm" target="_self" class="figure"> <div class="figure-box"> <img src="/images/lazy.gif" data-src="https://img.111cn.net/uploads/20241226/logo_676cb074f01b31.png" alt="街头搏斗 安卓最新版v3.2.2" /> </div> <p class="figure-head">街头搏斗 安卓最新版v3.2.2</p> <span class="figure-btn">下载</span> </a> </li> </ul> <ul class="card-box-b"> <li class="card10"> <a href="/app/101541.htm" target="_self" class="figure2"> <div class="figure-box"> <img src="/images/lazy.gif" data-src="https://img.111cn.net/uploads/20241226/logo_676cb08e8831a1.png" alt="我的博物馆故事 官方安卓版v1.61.2" /> </div> <div class="figure-cont"> <p class="figure-head">我的博物馆故事 官方安卓版v1.61.2</p> <div class="figure-desc"> <span>模拟经营</span> <span>我的博物馆故事 官方安卓版v1.61.2</span> </div> <div class="figure-desc"> <p>我的博物馆故事是一款以消除为主题的经营养成类手游,在这里玩家</p> </div> </div> <span class="figure-btn">下载</span> </a> </li> <li class="card10"> <a href="/app/101531.htm" target="_self" class="figure2"> <div class="figure-box"> <img src="/images/lazy.gif" data-src="https://img.111cn.net/uploads/20241226/logo_676cb07e2e4c11.png" alt="专业模拟飞行10 手机版v12.2.4" /> </div> <div class="figure-cont"> <p class="figure-head">专业模拟飞行10 手机版v12.2.4</p> <div class="figure-desc"> <span>模拟经营</span> <span>专业模拟飞行10 手机版v12.2.4</span> </div> <div class="figure-desc"> <p>专业模拟飞行10安卓版是一款飞行休闲手游,顶尖的物理飞行引擎</p> </div> </div> <span class="figure-btn">下载</span> </a> </li> <li class="card10"> <a href="/app/101526.htm" target="_self" class="figure2"> <div class="figure-box"> <img src="/images/lazy.gif" data-src="https://img.111cn.net/uploads/20241226/logo_676cb06f772b01.png" alt="动物起义战斗模拟器二琳同款 最新版v4.1.1" /> </div> <div class="figure-cont"> <p class="figure-head">动物起义战斗模拟器二琳同款 最新版v4.1.1</p> <div class="figure-desc"> <span>模拟经营</span> <span>动物起义战斗模拟器二琳同款 最新版v4.1.1</span> </div> <div class="figure-desc"> <p>动物起义战斗模拟器是一个非常有趣的模拟类游戏,玩家可以召唤各</p> </div> </div> <span class="figure-btn">下载</span> </a> </li> <li class="card10"> <a href="/app/101519.htm" target="_self" class="figure2"> <div class="figure-box"> <img src="/images/lazy.gif" data-src="https://img.111cn.net/uploads/20241226/logo_676cb05cef2841.png" alt="迷你世界七周年 安卓手机版v1.43.0" /> </div> <div class="figure-cont"> <p class="figure-head">迷你世界七周年 安卓手机版v1.43.0</p> <div class="figure-desc"> <span>模拟经营</span> <span>迷你世界七周年 安卓手机版v1.43.0</span> </div> <div class="figure-desc"> <p>迷你世界7周年是一款由《迷你世界》官方推出的庆祝特别版本,在</p> </div> </div> <span class="figure-btn">下载</span> </a> </li> <li class="card10"> <a href="/app/101514.htm" target="_self" class="figure2"> <div class="figure-box"> <img src="/images/lazy.gif" data-src="https://img.111cn.net/uploads/20241226/logo_676cb0544b9a61.png" alt="劫后公司无限资源版 v1.0.5.1" /> </div> <div class="figure-cont"> <p class="figure-head">劫后公司无限资源版 v1.0.5.1</p> <div class="figure-desc"> <span>模拟经营</span> <span>劫后公司无限资源版 v1.0.5.1</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>