Service Virtualization

Expand all | Collapse all

Unable to change XML tag attributes in response using Scripting expression

Jump to Best Answer
  • 1.  Unable to change XML tag attributes in response using Scripting expression

    Posted 11-15-2018 02:34 AM

    How can I use scripting expression to modify attribute of XML tag in the response?. Is there any another way to achieve same thing?

     

    for. e.g.

     

    <a id="1" timestamp="11/15/2018">

    some value

    </a>

     

    I have a requirement to modify attribute value id, timestamp of tag a of a response.

     

    Scripting expression {{=something}} is not working here.



  • 2.  Re: Unable to change XML tag attributes in response using Scripting expression

    Posted 11-15-2018 02:44 AM

    Try: ... id="{{something}}" ...

    That should be replaced by the value of an existing property called "something" if that property exists.

     

    If you really want to do "scripting" within the doublee curly braces then maybe better to share the script as there might be issues with the syntax or with the execution. You can scan the events or a log to find out if beansell was able to run the expression.

     

    From what you post, one initial remark already, if you put a "=" then you also need a semicolon at the end: {{=something;}}

     

    This is because if there is a equal sign it means it is an expression and an expression needs to be terminated by a semi-colon.

     

    Cheers,

    Danny



  • 3.  Re: Unable to change XML tag attributes in response using Scripting expression

    Posted 11-15-2018 04:02 AM

    Thanks Danny for your reply. I want to use magic string in the attribute. I tried with above syntax. It is printing text inside the double quote. e.g.

     

    I have requestorID as magic string in the request. I want to print it in the ID attribute of response. How can I do that?

     

    e.g

     

    Request:

     

    <a>

    <id>xyz</id>

    </a>

     

    Response:

    <b id="{{request_requestorID}}">

    some value

    </b>

     

    Thanks.



  • 4.  Re: Unable to change XML tag attributes in response using Scripting expression
    Best Answer

    Posted 11-15-2018 04:30 AM

    I just doublechecked it, it works ok, as expected.

     

     

     

    Some points to check:

     

       - In the .vsi in the arguments pane, is the checkbox “Magic String”

       checked for the argument “requestorID”

       - If so, can you doublecheck that the name used in response is exact

       name of argument, but additionally prefixed with “request_”

     

     

     

    Cheers,

     

    Danny

     

     

     

    From: k12345 <communityadmin@communities-mail.ca.com>

    Sent: donderdag 15 november 2018 10:02

    To: Danny Saro <sarda01@ca.com>

    Subject: Re:  - Re: Unable to change XML tag

    attributes in response using Scripting expression

     

     

    CA Communities <https://communities.ca.com/?et=watches.email.thread>

     

     

    Re: Unable to change XML tag attributes in response using Scripting

    expression

     

    reply from k12345

    <https://communities.ca.com/people/k12345?et=watches.email.thread> in *DevTest

    Community* - View the full discussion

    <https://communities.ca.com/message/242153632-re-unable-to-change-xml-tag-attributes-in-response-using-scripting-expression?commentID=242153632&et=watches.email.thread#comment-242153632>



  • 5.  Re: Unable to change XML tag attributes in response using Scripting expression

    Posted 11-15-2018 05:27 AM

    Hi Danny,

     

    Thanks for the help. It is working now. Do you know how to use scripting to update the response attribute?. 

     

    For e.g. I need to update the current timestamp in the specific format. For that I have written the beanshell code. Can we use beanshell code as well in double quotes?

     

    <a id="= import java.util.Date; Date d=new Date();........and so on">

    some value

    </a>



  • 6.  Re: Unable to change XML tag attributes in response using Scripting expression

    Posted 11-15-2018 06:04 AM

    Hi,

     

     

     

    When using the equal sign after the open curly braces what follows need to

    be a valid expression,

     

    {{=}

     

    I think the Date class is available in the beanshell scope, so something

    like following might work

     

    {{={Date d=new Date();........and so on };}}

     

     

     

    Cheers,

     

    Danny

     

     

     

    From: k12345 <communityadmin@communities-mail.ca.com>

    Sent: donderdag 15 november 2018 11:28

    To: Danny Saro <sarda01@ca.com>

    Subject: Re:  - Re: Unable to change XML tag

    attributes in response using Scripting expression

     

     

    CA Communities <https://communities.ca.com/?et=watches.email.thread>

     

     

    Re: Unable to change XML tag attributes in response using Scripting

    expression

     

    reply from k12345

    <https://communities.ca.com/people/k12345?et=watches.email.thread> in *DevTest

    Community* - View the full discussion

    <https://communities.ca.com/message/242153636-re-unable-to-change-xml-tag-attributes-in-response-using-scripting-expression?commentID=242153636&et=watches.email.thread#comment-242153636>



  • 7.  Re: Unable to change XML tag attributes in response using Scripting expression

    Posted 11-15-2018 08:51 AM

    Apologies, for the incoherent stuff above. I am replying from my email client and whole chunks of text are just discarded.

     

    The most important part that is missing was: search the documentation for doDateDeltaFromCurrent() function. This is a built-in utility function that allows you to generate a timestamp in any format you want (uses syntax similar to Java's SimpleDateFormat class)

     

    Cheers,

    Danny



  • 8.  Re: Unable to change XML tag attributes in response using Scripting expression

    Posted 11-16-2018 12:26 AM

    DevTest, by default, doesn't apply magic strings for attributes or anywhere inside XML tags. To allow magic strings inside XML tags, add the following property to your local.properties file in DevTest HOME directory (if local.properties doesn't already exist, then make a copy of _local.properties and rename it to local.properties):

     

    lisa.magic.string.xml.tags=true

     

    restart the registry/vse/workstation and it should now be able to apply magic strings inside XML tags.