How to apply a variable for an xml that is being sent as value in api testing

I am trying to make an API post-call where I have an HTTP body with x-www-form-urlencoded.

I have 6 Name and Value pairs entered, 1 of those name/value has an XML snippet that contains some data.

Now I want a way to apply some variables for some xml attributes and use them in a test case because I want those variable data to be coming from an excel sheet.

Sample XML added I want to make ID and Node as variables

<Product><Product AdjustmentType="Sync" ID="0783855" OrganizationCode="ECOMM" Quantity="1000" Node="00600" Type="ONHAND"/></Product>

can someone guide me on how to do this?

Just show us the full text of XML to parse. Provided with the XML, I would be able to show a sample code to parse the XML to select the attributes you want.

Thanks for the response!

Here you go! please let me know if this I what you were asking for

<Products>
   <Product AdjustmentType="Sync" ID="0783855" OrganizationCode="ECOMM" Quantity="1000" Node="00600" Type="ONHAND" />
</Products>

Converted to text online, i get the below

Products
Product
_AdjustmentType Sync
_ID 0783855
_OrganizationCode ECOMM
_Quantity 1000
_Node 00600
_Type ONHAND

import groovy.xml.XmlUtil

def xml = """<Products>
   <Product AdjustmentType="Sync" ID="0783855" OrganizationCode="ECOMM" Quantity="1000" Node="00600" Type="ONHAND" />
   <Product AdjustmentType="Sync" ID="8213704" OrganizationCode="FOOB" Quantity="99" Node="01840" Type="ONHAND" />
</Products>
"""

def products = new XmlSlurper().parseText(xml)

println XmlUtil.serialize(products)

assert products.size() == 1
assert products.'*'.size() == 2
assert products.'*'[0].'@ID' == '0783855'
assert products.'*'[0].'@Node' == '00600'
assert products.Product.size() == 2
assert products.Product[0].'@ID' == '0783855'
assert products.Product[0].'@Node' == '00600'

def id = products.Product[0].'@ID'
def node = products.Product[0].'@Node'
assert id == '0783855'
assert node == '00600'

products.Product.eachWithIndex { pr, index ->
	def attrID = pr.'@ID'
	def attrNode = pr.'@Node'
	println "${index}:   ID: ${attrID}"
	println "${index}: Node: ${attrNode}"
}

Output:

2021-10-23 08:53:43.163 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2021-10-23 08:53:43.166 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/surajigure09
2021-10-23 08:53:43.793 DEBUG testcase.surajigure09                    - 1: xml = "<Products>
   <Product AdjustmentType="Sync" ID="0783855" OrganizationCode="ECOMM" Quantity="1000" Node="00600" Type="ONHAND" />
   <Product AdjustmentType="Sync" ID="8213704" OrganizationCode="FOOB" Quantity="99" Node="01840" Type="ONHAND" />
</Products>
"
2021-10-23 08:53:43.796 DEBUG testcase.surajigure09                    - 2: products = XmlSlurper().parseText(xml)
2021-10-23 08:53:43.939 DEBUG testcase.surajigure09                    - 3: println(XmlUtil.serialize(products))
<?xml version="1.0" encoding="UTF-8"?><Products>
  <Product Type="ONHAND" Node="00600" Quantity="1000" OrganizationCode="ECOMM" ID="0783855" AdjustmentType="Sync"/>
  <Product Type="ONHAND" Node="01840" Quantity="99" OrganizationCode="FOOB" ID="8213704" AdjustmentType="Sync"/>
</Products>

2021-10-23 08:53:44.467 DEBUG testcase.surajigure09                    - 4: assert products.size() == 1
2021-10-23 08:53:44.476 DEBUG testcase.surajigure09                    - 5: assert *.size() == 2
2021-10-23 08:53:44.502 DEBUG testcase.surajigure09                    - 6: assert @ID == "0783855"
2021-10-23 08:53:44.557 DEBUG testcase.surajigure09                    - 7: assert @Node == "00600"
2021-10-23 08:53:44.559 DEBUG testcase.surajigure09                    - 8: assert Product.size() == 2
2021-10-23 08:53:44.574 DEBUG testcase.surajigure09                    - 9: assert @ID == "0783855"
2021-10-23 08:53:44.576 DEBUG testcase.surajigure09                    - 10: assert @Node == "00600"
2021-10-23 08:53:44.582 DEBUG testcase.surajigure09                    - 11: id = @ID
2021-10-23 08:53:44.585 DEBUG testcase.surajigure09                    - 12: node = @Node
2021-10-23 08:53:44.598 DEBUG testcase.surajigure09                    - 13: assert id == "0783855"
2021-10-23 08:53:44.602 DEBUG testcase.surajigure09                    - 14: assert node == "00600"
2021-10-23 08:53:44.603 DEBUG testcase.surajigure09                    - 15: Product.eachWithIndex({ java.lang.Object pr, java.lang.Object index -> ... })
0:   ID: 0783855
0: Node: 00600
1:   ID: 8213704
1: Node: 01840
2021-10-23 08:53:44.640 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/surajigure09

Reference: