开发者

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

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 tryin开发者_C百科g to achieve:

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

Thanks for any insight


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜