Forum Discussion

Sjakie's avatar
Sjakie
Occasional Contributor
15 years ago

add/remove elements from xml-request

For some time i have been looking for this. I hope someone can help me. I am looking if the Pro version is suitable for my company.

Because of the large number of request, I'm converting to a DataSource. The data is coming from Excel. The Request-message has a number of optional elements, but these have to be filled or not present.

How am I able to do this? With Groovy or with MockService? Could you give an example?

My idea is to get the value from the excel-datasource, see it if is null. If it is, remove the element.

Thanks in advance.
  • Sjakie's avatar
    Sjakie
    Occasional Contributor
    My project contains 4 steps. First is the DataSource, second my request, third is the DataSink and last is the DataSourceLoop.

    Do i have to insert the Groovy script after the DataSource? How do I get my request loaded in this script, so I can modifiy it? Do you have an example of this?
  • AnandKiran's avatar
    AnandKiran
    Frequent Contributor
    Hi,

    Try this pattern,
    1.First use your data source step to input all the requried values into the Request XML.
    2.Then add the groovy script --to check whether the Request XML has any empty nodes, if so then remove them. (you can get hold of your XML using this
    def request = context.expand( '${${operationname}#Request#//soapenv:Envelope}' )
    3.At last comes your data sink step.

    Sorry, I dont have any examples on this.

    Regards
    Anand
  • Sjakie's avatar
    Sjakie
    Occasional Contributor
    That's IT!!! With the context.expand(..) I can get my request, change what I need to and run the tests. Next step is figuring out the logging.

    Thank you very much!!