0

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

stealthyninja
  • 10,343
  • 11
  • 51
  • 59
Steve Kelly
  • 371
  • 3
  • 17

1 Answers1

2

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.

Cheeso
  • 189,189
  • 101
  • 473
  • 713
  • not easy for me, but it led me to [this answer](http://stackoverflow.com/questions/1118576/how-can-i-pretty-print-xml-source-using-vb6-and-msxml), which is exactly what I couldn't find in my searches. Thanks – Steve Kelly May 04 '11 at 14:16
  • You can run javascript on the server. change your opening script tag to this : – Dee May 04 '11 at 23:16