如何添加空格/格式化到VBScript中创建的XML? [英] How do I add whitespace/formatting to XML created in vbscript?

查看:203
本文介绍了如何添加空格/格式化到VBScript中创建的XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用VBScript编写的表单数据的XML文件:

I'm using vbscript to write form data to an XML file:

    Set objRecord = objDom.createElement("story")
    objRoot.appendChild objRecord


    Set objField = objDom.createElement("first")
    objField.Text = Request.Form("fName")
    objRecord.appendChild objField

这工作,但输出没有格式化,就像您从一个XML文件预期:

which works, but the output has no formatting like you would expect from an XML file:

    <story><first>Jennifer</first></story><story><first>David</first></story><story><first>Austin</first></story><story><first>Steve</first></story>

我想实现的:

    <story>
        <first>Jennifer</first>
    </story>
    <story>
        <first>David</first>
    </story>

感谢您的见解。

推荐答案

奥列格说:您可以pretty打印的现有的使用JavaScript这样的XML文件:

Oleg says You can pretty print an existing XML file using Javascript this way:

  var reader = new ActiveXObject("Msxml2.SAXXMLReader.4.0");
  var writer = new ActiveXObject("Msxml2.MXXMLWriter.4.0");        
  writer.indent = true;
  writer.standalone = true;
  reader.contentHandler = writer;            
  reader.putProperty("http://xml.org/sax/properties/lexical-handler", writer);
  reader.parseURL("source.xml");

这应该是pretty容易转化为VBScript。

That should be pretty easy to translate to VBScript.

这篇关于如何添加空格/格式化到VBScript中创建的XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆