hi, 

I've used script with slight changes from Tarun's book. My xml file in 
attachment


 Set xmlDoc = XMLUtil.CreateXMLFromFile("c:\example5.xml" )
        Set xmlRoot = xmlDoc.GetRootElement()
    Set xmlCols = xmlDoc.ChildElementsByPath("/info/person")
  ' ##########   count  future columns in the data table
  If xmlCols.Count <>0 Then
     Set xmlCol = xmlCols.item(1)
     iCount = xmlCol.ChildElements().Count
    msgbox iCount    
  ' #########  loop thru all elements and create column's name
  For i = 1 to iCount

     DataTable.GlobalSheet.AddParameter 
xmlCol.ChildElements.item(i).ElementName()," "
  
  Next
  '   ############  loop thru all nodes
  
  For i = 1 to xmlCols.count

   Set xmlCol = xmlCols.item(i)
   iCount = xmlCol.ChildElements().Count

   '  ########### loop thru  direct childrens
  
     For j = 1 to iCount
     sParamName = xmlCol.ChildElements.item(j).ElementName()
     sParamValue = xmlCol.ChildElements.item(j).Value()
     DataTable.GlobalSheet.SetCurrentRow (i)
      DataTable.GlobalSheet.GetParameter(sParamName).Value = sParamValue
   
    Next
  
          Next
  
  
  End If


Ludmila.


 



Date: Fri, 4 Sep 2009 21:40:21 +0530
Subject: Re: Extracting Values from XML and Exporting to DataTable
From: [email protected]
To: [email protected]



DataTable.Value ("Test", dtGlobalSheet) = root.nodeName

Try it
 
On Fri, Sep 4, 2009 at 7:40 PM, johnthenu <[email protected]> wrote:




<abc:Title>MISS</abc:Title>
<abc:FirstName>test</abc:FirstName>
<abc:Surname>case</abc:Surname>
<abc:Gender>FEMALE</abc:Gender>
<abc:DOB>1965-12-01</abc:DOB>
<abc:MaritalStatus>SING</abc:MaritalStatus>
<abc:LocalBorn>true</abc:LocalBorn>
<abc:LocalLivingStartDate>2000-01-01</abc:LocalLivingStartDate>
<abc:Status>EMP</tpf:Status>


Hi, I want to Extract text between <Title> tag and export it to
Datatable with Column Name Title_Name…..and I want to extract text
between <FirstName> tag and export the text to Datable with column
name First_Name and so on….

I have the below script which extract all the text between the child
elements, but I just want the text between individual elements and
export it to datatable in the respective column. Any Help will be very
much appreciated.

set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async= False
xmlDoc.load("C:\Documents and Settings\get\Desktop\test.xml")

Set root = xmlDoc.documentElement
For each x in root.childNodes
     DataTable.Value ("Test", dtGlobalSheet) = root.childNodes.item
(i).text
Next

Many Thanks,
<br


_________________________________________________________________
Get back to school stuff for them and cashback for you.
http://www.bing.com/cashback?form=MSHYCB&publ=WLHMTAG&crea=TEXT_MSHYCB_BackToSchool_Cashback_BTSCashback_1x1
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
"QTP - HP Quick Test Professional - Automated Software Testing"
group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/MercuryQTP?hl=en
-~----------~----~----~----~------~----~------~--~---

ÿþ<info young="lady" QTP="Great">

<person>

<Title>MISS</Title>

<FirstName>test</FirstName>

<Surname>case</Surname>

<Gender best="lady">FEMALE</Gender>

<DOB>1965-12-01</DOB>

<MaritalStatus>SING</MaritalStatus>

<LocalBorn>true</LocalBorn>

<LocalLivingStartDate>2000-01-01</LocalLivingStartDate>

<Status>EMP</Status>

</person>

<person>

<Title>MRS</Title>

<FirstName>test2</FirstName>

<Surname>case2</Surname>

<Gender notbest="guy">MALE</Gender>

<DOB>1946-12-01</DOB>

<MaritalStatus>MARRIED</MaritalStatus>

<LocalBorn>false</LocalBorn>

<LocalLivingStartDate>1999-12-12</LocalLivingStartDate>

<Status>UNEMP</Status>

</person>

<person>

<Title>Sir</Title>

<FirstName>test3</FirstName>

<Surname>case3</Surname>

<Gender best="lady">FEMALe_male</Gender>

<DOB>1932-12-09</DOB>

<MaritalStatus>MARRIED TWICE</MaritalStatus>

<LocalBorn>true</LocalBorn>

<LocalLivingStartDate>1989-01-01</LocalLivingStartDate>

<Status>BOSS</Status>

</person>

</info>

Reply via email to