I am a junior tester and I am using postman to chain together xml posts.
I have already had success with using global and environmental variables, however I am having a problem with extracting a child and its sub-child and then putting the whole chunk into my next post.
for example I have received the following
<?xml version="1.0" encoding="UTF-8"?>
<Example data="example"/>
<Demonstration filler="231" moreExample="true"/>
<Target>
<TargetSegment lettuce="true" onion="99" pickles="absolutely"/>
<TargetSubSegment potatoe="true"/>
</TargetSegment>
<TargetSegment chives="true" cabbage="99" celery="absolutely"/>
<TargetSubSegment turnip="true"/>
</TargetSegment>
</Target>
<Example2 data="example"/>
<Demonstration2 filler="231" moreExample="true"/>
How can i take everything inside of <Target>
and have that automatically placed into my next post body?
If you need any more information please let me know as this is my first time posting and I am still learning postman, and basically everything.
I have tried to do do JSON.stringify(variableName) (after I had converted xml to Json) and I didnt have any luck with that.
Frank, welcome to Stackoverflow! :D
The XML that you've posted here doesn't quite seem to be valid (checked it with a tool) and just to test it out and give you the following example, I wrapped your XML in a Data
tag to make it valid.
This is a collection that you can import in your postman app: https://www.getpostman.com/collections/d3f003de1376dc5d042b
Explanation:
I guess you're already using the xml2json
library that's built into the postman app. If you haven't used it yet then definitely check it out since it's required for your case.
Now, once you've imported the collection you can see in the first request that I've written some comments for you to understand what's happening.
You can convert the xml to json, extract out the target's data and store that in a variable.
In the next request (POST Request), you can refer to the environment variable inside the request body.
You can always reach out to the Postman Community too!
Update:
I have updated the collection and had to generate a new link (Import it again using the following link):
https://www.getpostman.com/collections/7660a47bc6fedaf5c5b7
I was able to find a script which converts json-to-xml and I hope it helps you out.
Check the Pre-request script of the collection and the request body of the 'POST' request.
Just converting the JSON data that was stored in the environment variable back to XML and storing it in a new environment variable.
Then referring that environment variable in the request body.
Script source (json2xml): http://goessner.net/download/prj/jsonxml/