我的操作系统是 Windows 7 64 位。我需要使用 VBScript 将以下 XML 字符串与解释的动态内容一起写入 XML 文件(同时维护制表符缩进):
文件名:[Variable1]_[Variable2].xml
<?xml version="1.0"?>
<config>
<modules>
<[Variable1]_[Variable2]>
<active>true</active>
<codePool>[Variable3]</codePool>
<version>[Variable4]</version>
</[Variable1]_[Variable2]>
</modules>
</config>
我所能尝试的只是在脚本下面一个一个地创建各种标签和元素。
scriptDir = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
Set xmlDoc = CreateObject("Msxml2.DOMDocument.3.0")
Set objRoot = xmlDoc.CreateElement("config")
xmlDoc.AppendChild objRoot
Set objRecord = xmlDoc.CreateElement("modules")
objRoot.AppendChild objRecord
Set objName = xmlDoc.CreateElement("Mageweb_ShippingFilter")
objName.Text = ""
objRecord.AppendChild objName
Set objDate = xmlDoc.CreateElement("AuditDate")
objDate.Text = Date
objRecord.AppendChild objDate
Set objIntro = xmlDoc.CreateProcessingInstruction("xml", "version='1.0'")
xmlDoc.InsertBefore objIntro, xmlDoc.ChildNodes(0)
'For now there is static name of file
xmlDoc.Save scriptDir & "\Testfile.xml"
但这对于将来可能的大型 XML 文件来说似乎太麻烦了,所以我可以将上面提到的 XML 字符串(所有变量都用它们的相关值解释)直接写入 XML 文件,然后给出一个基于变量的动态名称用VBScript?