Results 1 to 5 of 5
  1. #1

    Question about XMLElement.ChildElementsByPath

    I tried using XMLElement.ChildElementsByPath method to get a element, And then get a brother element.

    But I found I cannot get brother element if I use XMLElement.ChildElementsByPath.Item(1).NextSibling ...

    I guess provide my script can describe my question more clear. Please see below script:

    'Create XMLUtil object
    Set doc = XMLUtil.CreateXML

    'Load xml
    doc.Load "<Bookstore><Book><ISBN>1234 </ISBN></Book><Book><ISBN>4321</ISBN></Book><Book><ISBN>6584</ISBN></Book></Bookstore>"

    'root is Bookstore
    Set root = doc.GetRootElement

    'Use ChildElements method get the 3 "Book" elements collection
    Set children = root.ChildElements

    'Use ChildElementsByPath method get the 3 "Book" elements collection
    Set Xpathchildren = root.ChildElementsByPath("/Bookstore/*")

    'Here seems the ChildElements method the same as the ChildElementsByPath method
    For i = 1 to 3
    msgbox "children: " & children.Item(i).ElementName
    msgbox "Xpathchildren: " & Xpathchildren.Item(i).ElementName

    'When I use Xpathchildren.item(1) to find brother, I think I can get one "Book" element
    Set brother = Xpathchildren.Item(1).NextSibling

    'But it's nothing-.-!
    If brother is nothing Then
    msgbox "why!!!!!"
    End If

    'If I use the children.Item(1), It's fine to get a book element...
    Set brother = children.Item(1).NextSibling

    'Get it!
    msgbox brother.ElementName

    So, Is there anyone knows why I cannot get brother element "Book" by using children.Item(i).NextSibling? Many thanks!

  2. #2

    Re: Question about XMLElement.ChildElementsByPath


    Is this the functionality that you are looking for:

    Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
    objXMLDoc.async = False
    objXMLDoc.LoadXml "<Bookstore><Book><ISBN>1234 </ISBN></Book><Book><ISBN>4321</ISBN></Book><Book><ISBN>6584</ISBN></Book></Bookstore>"

    Set child1 = objXMLDoc.documentElement.firstChild
    Set child2 = child1.nextSibling
    msgbox child2.text

    Using the above method returns the 4321

  3. #3

    Re: Question about XMLElement.ChildElementsByPath


    Thanks for your reply, I know what you mean...

    But It's weird that cannot use root.ChildElementsByPath("/Bookstore/*").Item(1).NextSibling to get the sibling

  4. #4

    Re: Question about XMLElement.ChildElementsByPath

    Jank, this is a API developed specifically for QTP users. And there high chances such scenarios might not have been checked earlier. I would suggest you open a ticket with HP

  5. #5

    Re: Question about XMLElement.ChildElementsByPath

    OK~Thanks...Seems I found a bug-.-!

    I am going to tell HP...



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
BetaSoft Inc.
All times are GMT -8. The time now is 05:22 PM.

Copyright BetaSoft Inc.