vbscript 使用MSXML对象库创建XML

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vbscript 使用MSXML对象库创建XML相关的知识,希望对你有一定的参考价值。

' This procedure creates XML document
' and saves it to disk.
' Requires msxml.dll (Go to Project --> References and
' and choose Microsoft XML version 2.0, or whatever the
' current version you have installed)
' The example given below will write the following XML
' documents.
'
' <Family>
'    <Member Relationship="Father">
'       <Name>Some Guy</name>
'    </member>
' </family>
'
'but it should be clear how to modify the code
'to create your own documents

Private Sub Create_XML()
   
   Dim objDom As DOMDocument
   Dim objRootElem As IXMLDOMElement
   Dim objMemberElem As IXMLDOMElement
   Dim objMemberRel As IXMLDOMAttribute
   Dim objMemberName As IXMLDOMElement
   
   Set objDom = New DOMDocument
   
   ' Creates root element
   Set objRootElem = objDom.createElement("Family")
   objDom.appendChild objRootElem
   
   ' Creates Member element
   Set objMemberElem = objDom.createElement("Member")
   objRootElem.appendChild objMemberElem
   
   ' Creates Attribute to the Member Element
   Set objMemberRel = objDom.createAttribute("Relationship")
   objMemberRel.nodeValue = "Father"
   objMemberElem.setAttributeNode objMemberRel
   
   ' Create element under Member element, and
   ' gives value "some guy"
   Set objMemberName = objDom.createElement("Name")
   objMemberElem.appendChild objMemberName
   objMemberName.Text = "Some Guy"

   ' Saves XML data to disk.
   objDom.save ("c:\temp\andrew.xml")
End Sub

以上是关于vbscript 使用MSXML对象库创建XML的主要内容,如果未能解决你的问题,请参考以下文章

一个vc中使用msxml的问题

无法在 vbscript 中调用“HTMLFile”对象的 Body 属性

Paradox / ObjectPal 和 Microsoft XML Services (MSXML):调用某些方法时崩溃

21.1 XMLHttpRequest 对象JavaScript高级程序设计第三版

如何在VC中使用XML

怎样用vc++读写xml文件