简体   繁体   English

在机器人框架中将Web服务响应写入CSV文件

[英]write web service response in to csv file in robot framework

I want to take web service response in to csv file. 我想将Web服务响应输入到csv文件中。 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 ? 如何获取公司,城市,主地址,城市,州,邮政编码,zipplus4的值到csv文件中?

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. 您应该使用XML库来解析数据。 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. 由于这是一个xml字符串,因此可以使用XML库来处理该字符串。 In particular the section about Parsing XML should be of interest to you. 特别是您应该对有关解析XML的部分感兴趣。 It contains an example that you can adapt to your situation. 它包含一个可以适应您的情况的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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