7,785
社区成员




Private oXMLDom As MSXML2.DOMDocument
Private oXMLElement As MSXML2.IXMLDOMElement
Private oTemElement() As MSXML2.IXMLDOMElement
Private oNodeAttr As MSXML2.IXMLDOMAttribute
Private Sub Generate_Click()
Dim oThisNode As MSXML2.IXMLDOMNode
'<--Create a new DOMDoc and then set the root element
Set oXMLDom = CreateObject("MSXML2.DOMDocument")
oXMLDom.async = False
oXMLDom.validateOnParse = False
Set oXMLElement = oXMLDom.createElement("Root")
Set oXMLDom.documentElement = oXMLElement
'<--Create the child nodes and set the attributes(or values) if needed
ReDim oTemElement(0)
Set oTemElement(0) = oXMLDom.createElement("Node")
oXMLElement.appendChild oTemElement(0)
oTemElement(0).setAttribute "NodeAttr", "AttributeOfThisNode"
'<--Using dynamic object array to create nodes(attribute node)
ReDim Preserve oTemElement(UBound(oTemElement) + 1)
Set oTemElement(UBound(oTemElement)) = oXMLDom.createElement("ChildNode")
oTemElement(UBound(oTemElement) - 1).appendChild oTemElement(UBound(oTemElement))
Set oNodeAttr = oXMLDom.createAttribute("ChildNodeAttri")
oTemElement(UBound(oTemElement)).setAttributeNode oNodeAttr
oNodeAttr.Value = "ValueOfThisNodeAttr"
oTemElement(UBound(oTemElement)).Text = "Value Of this Element Node"
Save.Enabled = True
End Sub