网上的都是一堆引用的方法来实现的,而且超麻烦
这里我推荐下,不妨看看微软的msxml开发文档sdk,里面针对c/c++、vb、js、vbs都有很详细的说明和代码例子
虽然是英文版的但是看起来一点都不困难哈哈~~我特意传到csdn上去了,需要的人可以去下载,地址是:<包含从3.0~6.0之间的4个版本>
这里给出个例子:
Private Function CreateDOM()
Dim dom
Set dom = CreateObject("Microsoft.XMLDOM")
dom.async = False
dom.validateOnParse = False
dom.resolveExternals = False
dom.preserveWhiteSpace = True
Set CreateDOM = dom
End Function
Private Sub Form_Load()
Dim dom, node, attr
On Error GoTo ErrorHandler
Set dom = CreateDOM
' Create a processing instruction targeted for xml.
Set node = dom.createProcessingInstruction("xml", "version='1.0'")
dom.appendChild node
Set node = Nothing
' Create a processing instruction targeted for xml-stylesheet.
Set node = dom.createProcessingInstruction("xml-stylesheet", _
"type='text/xml' href='test.xsl'")
dom.appendChild node
Set node = Nothing
' Create a comment for the document.
Set node = dom.createComment("sample xml file created using XML DOM object.")
dom.appendChild node
Set node = Nothing
' Create the root element.
Dim root
Set root = dom.createElement("root")
' Create a "created" attribute for the root element and
' assign the "using dom" character data as the attribute value.
Set attr = dom.createAttribute("created")
attr.Value = "using dom"
root.setAttributeNode attr
Set attr = Nothing
' Add the root element to the DOM instance.
dom.appendChild root
' Insert a newline + tab.
root.appendChild dom.createTextNode(vbNewLine + vbTab)
' Create and add more nodes to the root element just created.
' Create a text element.
Set node = dom.createElement("node1")
node.Text = "some character data"
' Add text node to the root element.
root.appendChild node
Set node = Nothing
' Add a newline plus tab.
root.appendChild dom.createTextNode(vbNewLine + vbTab)
' Create an element to hold a CDATA section.
Set node = dom.createElement("node2")
Set cd = dom.createCDATASection("")
node.appendChild cd
Set cd = Nothing
dom.documentElement.appendChild node
Set node = Nothing
' Add a newline plus tab.
root.appendChild dom.createTextNode(vbNewLine + vbTab)
' Create an element to hold three empty subelements.
Set node = dom.createElement("node3")
' Create a document fragment to be added to node3.
Set frag = dom.createDocumentFragment
' Add a newline + tab + tab.
frag.appendChild dom.createTextNode(vbNewLine + vbTab + vbTab)
frag.appendChild dom.createElement("subNode1")
' Add a newline + tab + tab.
frag.appendChild dom.createTextNode(vbNewLine + vbTab + vbTab)
frag.appendChild dom.createElement("subNode2")
' Add a newline + tab + tab.
frag.appendChild dom.createTextNode(vbNewLine + vbTab + vbTab)
frag.appendChild dom.createElement("subNode3")
' Add a newline + tab.
frag.appendChild dom.createTextNode(vbNewLine + vbTab)
node.appendChild frag
Set frag = Nothing
root.appendChild node
' Add a newline.
root.appendChild dom.createTextNode(vbNewLine)
Set node = Nothing
' Save the XML document to a file.
dom.save App.Path + "\dynamDom.xml"
Set root = Nothing
Set dom = Nothing
Exit Sub
ErrorHandler:
MsgBox Err.Description
End Sub
阅读(254) | 评论(0) | 转发(0) |