SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 6 of 6
  1. #1
    Moderator
    Join Date
    Sep 2001
    Location
    Doncaster, UK
    Posts
    5,788
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    XML Child Object Issue

    I'm trying to access the value of an XML child object in the following structure:

    <root>
    ...<parent>
    ......<child>

    Child is defined as:
    <LID>123456789</LID>

    Using the following code I can get the whole tag but am sruggling to get just the value:

    '=======================================
    Set doc = XMLUtil.CreateXML()
    doc.LoadFile "D:\test.xml"

    Set root = doc.GetRootElement()
    Set children = root.ChildElements()

    myPath = "//data/row/LID"

    Set element = doc.ChildElementsByPath(myPath)

    for i = 1 to element.Count
    MsgBox element.Item(i)
    next
    '============================================

    I'm looking for something like element.Value(i) but that is invalid

    Mark Smith.

  2. #2
    Senior Member
    Join Date
    Jan 2006
    Location
    Stockholm, Sweden
    Posts
    371
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: XML Child Object Issue

    Try XML DOM instead:

    Set xmlDoc = CreateObject("Msxml2.DOMDocument")

    'loadXML Note! use Load instead if xml is in a file

    xmlDoc.loadXML("yourXML")

    'Check XML syntax

    If (xmlDoc.parseError.errorCode <> 0) Then

    Set myErr = xmlDoc.parseError

    Msgbox "ERROR: " & myErr.reason

    End If

    Set root = xmlDoc.documentElement

    'Select element(s) using Xpath

    Set nodes = root.selectNodes("//LID")

    Msgbox nodes.Item(0).text

    Set nodes = Nothing

  3. #3
    Moderator
    Join Date
    Sep 2001
    Location
    Doncaster, UK
    Posts
    5,788
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: XML Child Object Issue

    Thanks Stefan that worked perfectly (and executes quicker than QTPs XMLUtil)/

    Mark Smith.

  4. #4
    Member
    Join Date
    Oct 2003
    Location
    Norfolk, VA
    Posts
    360
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: XML Child Object Issue

    I believe (for reference sake using QTP XMLUtil) the correct syntax would be: element.Item(i).value, not element.Value(i)
    A good rule of thumb is to never measure with your thumb.

  5. #5
    Senior Member
    Join Date
    Jan 2006
    Location
    Stockholm, Sweden
    Posts
    371
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: XML Child Object Issue

    You're welcome [img]/images/graemlins/smile.gif[/img]

    I am not that impressed when it comes to QTP and performance as you can read here

  6. #6
    Moderator
    Join Date
    Jan 2007
    Location
    Pittsburgh, PA
    Posts
    2,497
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: XML Child Object Issue

    My Experience with QTP performance............
    Recently I have received testdata in a text file from my system admin. The file has 360000 lines in which I need to read the data line by line and separate it(with some logic) and write into an excel. I have written a vbscript to do my job.

    QTP has taken 10+hours to complete the job execution.
    VBS editor has taken only 2 minutes to complete the job execution.

    Thanks,
    -Reddy

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 10.71%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 07:49 PM.

Copyright BetaSoft Inc.