2011-05-04 48 views
0

我使用VBScript表單數據寫入到一個XML文件:如何將空格/格式添加到在vbscript中創建的XML中?

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


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

它的工作原理,但輸出沒有格式化,就像您從一個XML文件中預計:

<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> 

感謝任何見解

回答

2

Oleg says您可以使用JavaScript這樣漂亮的打印現有 XML文件:

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

這應該是很容易轉化爲VBScript。

+0

對我來說不是件容易的事,但它將我引向[這個答案](http://stackoverflow.com/questions/1118576/how-can-i-pretty-print-xml-source-using-vb6-and- msxml),這正是我在我的搜索中找不到的。謝謝 – 2011-05-04 14:16:38

+0

你可以在服務器上運行javascript。 更改您的開幕腳本標記爲:

相關問題