Welcome, Guest. Please login or register.
Login with username, password and session length

 
Advanced search

18120 Posts in 4741 Topics- by 31743 Members - Latest Member: suuraj
 

Pages: [1]   Go Down
Print
0 Members and 1 Guest are viewing this topic.
Author Topic: need to find a specific item in XML file and extract one of its child nodes    (Read 404 times)
Donna Scharkss
User
*
Offline Offline

Posts: 10


« on: January 05, 2010, 12:21:05 PM »

Not sure which forum to put this in.  We're using Java but XML questions seem to be web questions, which we're not using.  Hope someone would have the code needed to work this.

Anyway, I have an .xml file, about 12 mb long.  Using QTP 10, I need to search within the xml file for a specific item (only one of that item will exist in the file).  The data will be in a child node (about 3 levels within the parent node).  Then, within that parent node, I need to extract a bit of information from another child node on the same level as the search result node.

I know the tag names.  I need to get the data from that tag within the parent node selected from the search.

I also have use of the .jar file if QTP has ways to access the public functions in it.  Would you have information on how/if QTP can do this?

Thank you so much.
Logged
mjp
User
*
Offline Offline

Posts: 47


« Reply #1 on: January 25, 2010, 11:34:44 AM »

Hi Donna,
You can use Microsoft's MsXML2 object to work with xml files.
Code:
Set xmlDoc = CreateObject("Msxml2.DOMDocument.3.0")
xmlDoc.async="false"
xmlDoc.validateOnParse = False
xmlDoc.Load( YourLibraryFile)
Set objCol = xmlDoc.documentElement.selectNodes(strXPath)

For Each e In objCol 'loop over the elements
Set objFields = e.selectNodes("field")
For Each f In objFields 'loop over the field elements
    sFieldName = f.getAttribute("fieldName")
    sFieldLabel = f.getAttribute("fieldLabel")
'etc ...
QTP also has an XMLData object. (I have not used it.)
Regards,
M.
Logged
Breakman
User
*
Offline Offline

Posts: 1


« Reply #2 on: April 12, 2010, 09:09:34 AM »

I have been able to open an xml as a scripting object.  Basically I read each line looking for the start and end tags then extract the value in between.  Something like this.

set obFSOof = CreateObject ("Scripting.FileSystemObject")
' open the file
set OpenxmlFile = obFSOof.OpenTextFile(somexml(LoopCTR), 1, True)
   do
      strxmlline = OpenxmlFile.ReadLine
      intpos1 = InStr(1, strxmlline, "<ut:TagValue>",1)
      If intpos1> 0 Then
       intpos2 = instr(intpos1,strxmlline,"</ut:EndTagValue>")
       tmpString = mid(strxmlline, (intpos1), (intpos2 - (intpos1)))
       boolFound = True
      end if
   loop until boolFound
Logged
Pages: [1]   Go Up
Print
Jump to: