Forum Discussion

LZhang's avatar
LZhang
Frequent Contributor
16 years ago

How to dynamically select a node from xml response

Hi:

I have a following response:


             
                  fba589f7-fe27-471b-94fa-caf1a69532c4
                  true
Notif92116434243@fakeabchost.net
                  HTMLEmail
                  2008-10-21T23:43:11Z
             

             
                  fa94ec92-dff4-4e75-a73e-d4e2f05ea417
                  true
                  3164316118
                  PlainTextSMS
                  2008-10-21T23:43:18Z
             

           


Every time when the response is returned, the order of the two NotificationTarget nodes changes.  For example, I have a property transfer to obtain DeliveryFormat from node 1, which is HTMLEmail to another request.  The next time when I run the same steps, node 1 can become node 2, which is PlainTextSMS and it gets transferred to subsequent request and then my test case would fail.  Is there a way to dynamically transfer the xml node based on specified string?  For example, search the xml response and find me the deliveryformat that is "HTMLEmail"?


Regards,
Li Zhang

3 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Li,

    sure, you can add a check for this in your xpath, for example (without namespaces);

    //NotificationTarget[DeliveryFormat='HTMLEmail']/NotificationTargetId

    would select the NotificationTargetId of the NotificationTarget with the DeliveryFormat set to 'HTMLEmail', indepent of its order in the document..

    Does this help?

    regards!

    /Ole
    eviware.com
  • LZhang's avatar
    LZhang
    Frequent Contributor
    Hi:

    Can I just do it directly at the property transfer step or do I need to write a groovy code for it?

    Here is the xpath:

    declare namespace ns1='http://services.tvguide.com/v6/notifications';
    //ns1:GetNotificationTargetsResponse[1]/ns1:GetNotificationTargetsResult[1]/ns1:NotificationTargets[1]/ns1:NotificationTarget[1]/ns1:NotificationTargetId[1]

    I tried different combinations but didn't seem to work.  Should I have the following?

    declare namespace ns1='http://services.tvguide.com/v6/notifications';
    //ns1:GetNotificationTargetsResponse[1]/ns1:GetNotificationTargetsResult[1]/ns1:NotificationTargets[1]/ns1:NotificationTarget[DeliveryFormat='HTMLEmail']/ns1:NotificationTargetId[1]

    Regards,
    Li