XMLAddNode

Top  Previous  Next

Method

XMLAddNode(oNode, strXML)

Parameters

oNode (Node object in the document), strXML (the XML to add as a child node)

Returns

Object (DOM Node)

 

The XMLAddNode() method allows you to use a valid XML string to create a CHILD node of an existing node of an XML document.

 

Example VBScript Code

 

Private Sub DemoXML()

 

Dim oXML, ndRoot, ndChild

Dim sBuff, sXML, i

 

'Create the object

Set oXML = oUTILITIES.NewCommandoXMLObject()

 

'Using the With / End With statements make for easy shortcuts

With oXML

   'STEP 1

   sBuff = "<EXAMPLE></EXAMPLE>"

   .OpenFromString sBuff

   Set ndRoot = .GetRootElement()   .SetAttribute ndRoot, "DATE", oUTILITIES.VBFormat(Now, "dd mmm yyyy")

   'Add Some Child Nodes

   sBuff = "<EXCHILD></EXCHILD>"

   For i = 1 To 10 

        Set ndChild = .XMLAddNode(ndRoot, sBuff)

        .SetAttribute ndChild, "INDEX", i

   Next   

   'Show the XML

   MsgBox .XML, vbInformation, "The CommandoXML Object"

   'STEP 2

   'Store the XML in a variable for a minute

   sXML = .XML

   'Now we'll create another document to show how flexible we can be

   sBuff = "<NEWDOC></NEWDOC>"

   .OpenFromString sBuff

   Set ndRoot = .GetRootElement()

   .SetAttribute ndRoot, "TIME", oUTILITIES.VBFormat(Now,"hh:nn:ss AMPM")

   'Now watch carefully, we're going to add the entire XML document

   'we created in step 1 as a child node of ndRoot in the document we

   'just created.

   Set ndChild = .XMLAddNode(ndRoot, sXML)

   'Show the XML

   MsgBox .XML, vbInformation, "The CommandoXML Object"

 

 

 

End With

'Clean up the objects

Set ndRoot = Nothing

Set ndChild = Nothing

Set oXML = Nothing

 

End Sub

 

See Also: oUTILITIES.NewCommandoXMLObject()