Micro Focus QTP (UFT) Forums
XML Read Functions - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: XML Read Functions (/Thread-XML-Read-Functions)



XML Read Functions - Nish - 11-25-2011

Iam a beginner in QTP and working for Energy services in Europe and the reason in writing this mail is i am facing problem in writing functions for reading data from our test harness scripts in which we get the result in an XML file .

The requirement/task was

it will be easiest to be pass down the full path name from the server for the file, as each night part of the test server set up is to copy all the files
A number of new QTP functions require to be written to support the a number of the user stories. These functions will read the ASA test harness script(Testdata XML and extract the following information:

- The Switching List bounded by <SwitchingList> and </SwitchingList>

- The Circuit Information for each Possible Restoration options held. Information to be captured for this function will be:

For each Potential Outage ID

- Possible Restoration details - There may be more than one set of possible restoration options for a given outage

- The full circuit information (There may be more than one circuit per Possible Restoration block)



[/quote]as mentioned above i need to pass these values to GUI and get the result which matches the xml data which i have attached to this post..[attachment=861]



RE: XML Read Functions - nil111 - 11-26-2011

Use Following function to reading data from the XML
U have to pass the XML file name and Node name as argument for this function
Hope this will help you.
With Best Regards,
Nil111

Code:
Function Fn_GetXMLNodeValue(XMLDataFile, sNodeName)

    Dim objXMLDoc
    Dim objChildNodes
    Dim objSelectNode
    Dim intNodeLength
    Dim intNodeCount
    Dim intChildNodeCount
    Dim strNodeSting

    set objXMLDoc=CreateObject("Microsoft.XMLDOM")                                                ' Create XMLDOM object
    objXMLDoc.async="false"
    objXMLDoc.load(XMLDataFile)                                                                    ' Loading QTP Environment XML

    If (objXMLDoc.parseError.errorCode <> 0) Then
        Fn_GetXMLNodeValue = False
    Else
        intNodeLength = objXMLDoc.getElementsByTagName("Variable").length
        For intNodeCount = 0 to (intNodeLength - 1)
            Set objChildNodes = objXMLDoc.documentElement.childNodes.item(intNodeCount).childNodes
                strNodeSting = ""
                For intChildNodeCount = 0 to (objChildNodes.length - 1)
                        strNodeSting = strNodeSting & objChildNodes(intChildNodeCount).text
                Next
                If Instr(strNodeSting, sNodeName) Then
                    Set objSelectNode = objXMLDoc.SelectSingleNode("/Environment/Variable[" & intNodeCount &"]/Value")
                    Fn_GetXMLNodeValue = objSelectNode.Text
                    Exit For
                End If
        Next
        Set objSelectNode = nothing
        Set objChildNodes = nothing
        Set objXMLDoc = nothing

        If Fn_GetXMLNodeValue = "" Then
            Fn_GetXMLNodeValue = False
        End If
    
    End if    

End Function



RE: XML Read Functions - Nish - 11-26-2011

i
Many Thanks NIL for ur Reply...and as u said i have the file name and node name to the function as below and res is giving false when i ran the code...my actual doubt is how to read data from the list and populate the into a data table in QTP so that i can grab the data from the data table into the script and verify the result with some other elements in the same XML file ( i have attached)
kindly elaborate with ref to my xmlfile...


Code:
Dim res

res = Fn_GetXMLNodeValue ("E:\Documents and Settings\MNB\Desktop\TestData.xml","SwitchingList")


msgbox res