简体   繁体   中英

write web service response in to csv file in robot framework

I want to take web service response in to csv file. For eg : This is the response.

<address><company>ABC</company><urban></urban>
<primaryaddress>ABCDEFG</primaryaddress><city>XYZ</city><state>WA</state>
<zip>11111</zip><zipplus4>8888</zipplus4></address>

How to get values for company, urban, primaryaddress, city, state, zip, zipplus4 in to the csv file ?

right now I am using substring as below:

    ${Company}  Split String  ${GetCAResult}  <company>
    Create File  ${EXECDIR}/file_with_variable.csv   ${GetCAResult.company}

doing substring for every value does not seem to be solution. is there any other way to get values ?

You should use the XML library to parse the data. For example:

${GetCAResult}=  Get the data

${address}=  Parse XML  ${GetCAResult}
${company}=  Get element   ${address}  company
${city}=     Get element   ${address}  city
${state}=    Get element   ${address}  state

Create File  ${EXECDIR}/file_with_variable.csv   
...    ${company.text}, ${city.text}, ${state.text}

As this is an xml string, you can use the XML Library to process the string. In particular the section about Parsing XML should be of interest to you. It contains an example that you can adapt to your situation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM