I am working on a groovy script in which I have to take values from request XML file and write those into XML response file.
I know how to read values from normal XML as given below:
def text = '''
<list>
<technology>
<name>Groovy</name>
</technology>
</list>
'''
def list = new XmlParser().parseText(text)
println list.technology.name.text()
I can easily access nodes using above syntax. But in my case the request file have 'keyword:label' syntax. Consider below mentioned request file for currency converter:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://www.webserviceX.NET/">
<soap:Header/>
<soap:Body>
<web:ConversionRate>
<web:FromCurrency>USD</web:FromCurrency>
<web:ToCurrency>INR</web:ToCurrency>
</web:ConversionRate>
</soap:Body>
</soap:Envelope>
How to read value of FromCurrency
in this case? Instead of using XMLParser, is there any other efficient and good way to handle larger XML files?
Also, while writing values in the response I am writing by creating multiple variables in script and using their values in response using syntax "${var_name}.
If I want to write many values (suppose 20+) from request into response, then variable for individual writing is not good way. So is there any good and efficient way for this?