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: Access node attricute values of XML    (Read 277 times)
niranjan deka
FRProject
Full User
*
Offline Offline

Posts: 226


« on: February 02, 2010, 04:24:39 AM »

Hi all,

I need to access class node attibute value /name and properties of the xml file. Can anyone know how to do it using pure vbscript form. I don't want to use Dot net factory method.

sFileName="c:\OR.xml"

Set objXML= CreateObject("Microsoft.XMLDOM")
objXML.async = False
objXML.load sFileName


Set oRoot = objXML.documentElement.childNodes.item(0).childNodes

For each child in oRoot

   msgbox child.nodename

Next


Thanks

regards
Niranjan
Logged
Manoj Kulkarni
Full User
***
Offline Offline

Posts: 238



« Reply #1 on: February 02, 2010, 04:40:12 AM »

Hi,
  If you know the atrribute names then use for each attribute.
  objChldNode.Attributes.GetNamedItem(AttrName).NodeTypedValue

P.S. - Attached zip is damaged.
Logged

Regards,
Manoj Smiley
Asiq Ahamed
Moderator
Sr. User
*****
Offline Offline

Posts: 459



WWW
« Reply #2 on: February 02, 2010, 04:55:41 AM »

Hi Niranjan,
        I haven't seen your attached XML. Plese try the below code, if it is comfortable with your XML,

Code
GeSHi (qtp):
gStrOrPath="c:\"'Path of your XML

Set gObjXmlOR = CreateObject( "Microsoft.XMLDOM")

gObjXmlOR.Async = "False"

gObjXmlOR.Load(gStrOrPath)

v_Str_X_Query="/xx/yy"'Write your query here

Msgbox gObjXmlOR.documentElement.selectSingleNode(v_Str_X_Query).attributes(0).Text

 
Created by GeSHI 1.0.7.20
Logged
niranjan deka
FRProject
Full User
*
Offline Offline

Posts: 226


« Reply #3 on: February 02, 2010, 09:50:18 PM »

Thanks a lot guys...

I am herewith attaching the zipped contents again....Please have a look and let me know your views.

Regards
Niranjan
Logged
Asiq Ahamed
Moderator
Sr. User
*****
Offline Offline

Posts: 459



WWW
« Reply #4 on: February 05, 2010, 09:12:22 AM »

Hi Niranjan,
        I have written sample code as per your requirement.

Code
GeSHi (qtp):
gStrOrPath="C:\Documents and Settings\Desktop\Testor.xml"'Path of your XML



Set gObjXmlOR = CreateObject( "Microsoft.XMLDOM")



gObjXmlOR.Async = "False"



gObjXmlOR.Load(gStrOrPath)



v_Str_X_Query="/qtpRep:ObjectRepository/qtpRep:Objects/qtpRep:Object[@Class='Dialog' and @Name='Login']" 'Write your query here



childCount= gObjXmlOR.documentElement.selectSingleNode(v_Str_X_Query).childNodes(0).childnodes.length-1



For i=0 to childCount

        Msgbox gObjXmlOR.documentElement.selectSingleNode(v_Str_X_Query).childNodes(0).childnodes(i).text

Next



 
Created by GeSHI 1.0.7.20

This is what you want right?
Logged
niranjan deka
FRProject
Full User
*
Offline Offline

Posts: 226


« Reply #5 on: February 10, 2010, 03:03:21 AM »

Hi Asiq,

Thanks a lot for your time. I am really a dump in xml. I have tried your code. But giving error. My intenstion is to retrieve all name and values of node 'qtpRep:Object' class.

Regards
Niranjan
Logged
Asiq Ahamed
Moderator
Sr. User
*****
Offline Offline

Posts: 459



WWW
« Reply #6 on: February 11, 2010, 06:17:49 AM »

Hi Niranjan,
        Try this,
Code
GeSHi (qtp):
gStrOrPath="C:\Documents and Settings\Testor.xml"'Make sure about your XML Path



Set gObjXmlOR = CreateObject( "Microsoft.XMLDOM")



gObjXmlOR.Async = "False"



gObjXmlOR.Load(gStrOrPath)



Set oClass= gObjXmlOR.DocumentElement.getElementsByTagName("qtpRep:Object")



For i=0 to oClass.Length-1

        Msgbox oClass(i).attributes(0).Name & " " & oClass(i).attributes(0).Text'Here class name and value are displayed

Next



Set gObjXmlOR = Nothing

 
Created by GeSHI 1.0.7.20
Logged
niranjan deka
FRProject
Full User
*
Offline Offline

Posts: 226


« Reply #7 on: February 16, 2010, 08:45:03 PM »

Hi Asiq,

Thanks a lot for the post. I couldn't imagine that the solution will be so simple.
yes, i got what i wanted to retrieve.

Once again appreciate your help.

regards
Niranjan
Logged
Pages: [1]   Go Up
Print
Jump to: