How do I add whitespace/formatting to XML created in vbscript?

烈酒焚心 提交于 2019-12-08 10:38:19

问题


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

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>

I'm trying to achieve:

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

Thanks for any insight


回答1:


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");

That should be pretty easy to translate to VBScript.



来源:https://stackoverflow.com/questions/5883655/how-do-i-add-whitespace-formatting-to-xml-created-in-vbscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!