GetRootChildren()

Top  Previous  Next

Object: EHL7.QSXML

FileName: EHL7.dll

 

METHOD

 

Name: GetRootChildren()

Parameters: None

Returns: Object (See below)

Description: This method returns the nodeList of all children of the root element, returns Nothing if the root element has no children and isError is set to True.

 

*XML Note: The object returned is actually of type "MSXML2.IXMLDOMNodeList" and is the functional equivalent of calling the .childNodes method of an item of type "MSXML2.IXMLDOMNode"

 

Example:

Dim myXMLObj As New EHL7.QSXML

Dim strXML As String

Dim ndRT As Object

Dim ndChildren As Object

Dim i As Long

With myXmlObj

.ClearErrors

strXML = "<GOODXML></GOODXML>"

Call .OpenFromString(strXML)

If .IsError Then

  MsgBox .LastError

  .ClearErrors

  Exit Sub

End If

Set ndChildren = .GetRootChildren()

'ndChildren is now nothing and IsError is True because the root had no children.

If .IsError Then

   MsgBox .LastError

   .ClearErrors

End If

'Add 3 child nodes

strXML = "<CHILD></CHILD>"

Set ndRT = .GetRootElement()

Call .XMLAddNode ndRT,strXML

Call .XMLAddNode ndRT,strXML

Call .XMLAddNode ndRT,strXML

'Get the children again

Set ndChildren = .GetRootChildren()

'Or I could just use MSXML code on the ndRT object

'Set ndChildren = ndRT.ChildNodes

  'Remember that objects of type IXMLDOMNodeList are a 0 based Array

For i = 0 To ndChildren.Length -1

  'Set an attribute

  .SetAttribute ndChildren(i), "ITEMNUMBER", CStr(i)

Next

'Show the attribute I just set

For i = 0 To ndChildren.Length -1

   MsgBox "Child Node: " & .GetAttributeValue(ndChildren(i), "ITEMNUMBER")

Next

End With

Set myXMLObj = Nothing