GetNodeFromAttribute() |
Top Previous Next |
Object: EHL7.QSXML FileName: EHL7.dll
METHOD
Name: GetNodeFromAttribute() Parameters:
Returns: XML Node Object or Nothing if not found. Description: This method returns the first occurrence of a node within a the nodelist objNodeList that has the attribute strAttribute with the value strValue.
Note: The attribute name and the value are NOT case sensitive in this method. So: GetNodeFromAttribute(ndLst,"name","homer") ... is the functional equivalent of: GetNodeFromAttribute(ndLst,"NAME","HOMER")
See Also: VendorsXML(), SetAttribute()
Example to Populate a VB listbox with vendors to allow user selection: '1) Create a blank form and place a listbox control on it called listbox1 'In the form declaration area Private myVendorsXML As String
Private Sub Form_Load() Dim myVendorObj As New EHL7.HL7Vendors Dim oXML As New EHL7.QSXML Dim ndRT As Object Dim ndLst As Object Dim i As Long Dim sBuff As String Dim strVendorID As String myVendorObj.VendorPath = "C:\EasyHL7" myVendorsXML = myVendorObj.VendorsXML() If myVendorsXML = "" Then MsgBox myVendorObj.LastError Exit Sub End If oXML.OpenFromString(myVendorsXML) Set ndRT = .GetRootElement() If CLng(.GetAttributeValue(ndRT,"COUNT","0")) = 0 Then MsgBox "No Vendors Installed" Exit Sub End If Set ndLst = .GetRootChildren For i = 0 To ndLst.Length - 1 sBuff = .GetAttributeValue(ndLst(i),"NAME") & _ " (Version " & .GetAttributeValue(ndLst(i),"VERSION") & ")" listbox1.AddItem sBuff 'We'll use the item data property to store the index so 'you can set the .sorted property on the listbox to True if desired listbox1.ItemData(listbox1.NewIndex) = i Next Set myVendorObj = Nothing Set oXML = Nothing End Sub 'Now add DblClick code to the listbox Private Sub listbox1_DblClick() Dim myVendorObj As New EHL7.HL7Vendors Dim oXML As New EHL7.QSXML Dim ndRT As Object Dim ndVendor As Object Dim ndLst As Object Dim i As Long Dim idxSel As Long Dim strVendorID As String 'Get our node index for the selected vendor idxSel = listbox1.ItemData(listbox1.ListIndex) myVendorObj.VendorPath = "C:\EasyHL7" With oXML 'Load the vendors xml we saved in form_load .OpenFromString(myVendorsXML) 'Get the root children Set ndLst = .GetRootChildren() 'NOW WE KNOW WHICH VENDOR THE USER CLICKED strVendorID = .GetAttributeValue(ndLst(idxSel),"ID") MsgBox "The user selected Vendor ID: " & strVendorID 'We can also call Set ndVendor = .GetNodeFromAttribute(ndLst,"ID",strVendorID) End With With myVendorObj Call .OpenVendor(strVendorID) 'etc 'etc End With
End Sub
Example XML String: <VENDORS COUNT="3"> <VENDOR ID="63578DEA-9541-4663-B484-111919054FBC" NAME="Default" DESCRIPTION="EasyHL7 default vendor for version 2.3" VERSION="2.3" FIELDSEPARATOR="|" ENCODINGCHARS="^~\&" /> <VENDOR ID="10D80A28-6A2C-4AD3-8080-32924F02F0CE" NAME="Default" DESCRIPTION="" VERSION="2.4" FIELDSEPARATOR="|" ENCODINGCHARS="^~\&" /> <VENDOR ID="5ABE45FC963631449F077FA15F28E69B" NAME="Labcorp" DESCRIPTION="Labcorp vendor created by me" VERSION="2.3" FIELDSEPARATOR="|" ENCODINGCHARS="^~\&" /> </VENDORS>
|