Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
XML Read Functions
#1
Not Solved
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..
.txt   New Text Document (5).txt (Size: 17.38 KB / Downloads: 96)
Reply
#2
Not Solved
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
Reply
#3
Not Solved
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Inserting variable values into Descriptive Programming Functions eske99 2 3,569 12-18-2015, 01:47 PM
Last Post: vinod123
  Passing objects to Functions vinod.nhce 0 3,323 03-13-2014, 06:09 PM
Last Post: vinod.nhce
  vb script to stop execution of functions if conditions fail visitjaga 1 7,460 12-05-2013, 12:26 AM
Last Post: ravi.gajul
  Getting an 'Error in XML document' Error when submitting web services XML luckyexpert 0 3,155 08-20-2013, 10:23 PM
Last Post: luckyexpert
  XML Data read and extract output in an array SweetyChowdhury 9 7,862 05-10-2013, 03:05 PM
Last Post: SweetyChowdhury

Forum Jump:


Users browsing this thread: 1 Guest(s)