database - 无法正确循环 groovy 中的 XML 标签

标签 database groovy soapui

我能够通过 soapUI 发送一个网络请求,它以 XML 格式提供数据作为响应。我想在数据库表中插入 xml 标记的值。

这是我试过的:

def response = context.expand('${Request1#Response}')


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

“响应”变量的内容:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:sawsoap="urn://oracle.bi.webservices/v7">
<soap:Body>
<sawsoap:executeXMLQueryResult>
         <sawsoap:return xsi:type="sawsoap:QueryResults">
<sawsoap:rowset xsi:type="xsd:string"><![CDATA[<rowset xmlns="urn:schemas-microsoft-com:xml-analysis:rowset">

<Row>
<Column0>John</Column0>

</Row>

<Row>

    <Column0>Max</Column0>
</Row>
</rowset>]]></sawsoap:rowset>
<sawsoap:queryID xsi:type="xsd:string">RSXS4_1</sawsoap:queryID>
<sawsoap:finished xsi:type="xsd:boolean">true</sawsoap:finished>
</sawsoap:return>
 </sawsoap:executeXMLQueryResult>
</soap:Body>
</soap:Envelope>

“xml”的内容:

<rowset xmlns="urn:schemas-microsoft-com:xml-analysis:rowset">
<Row>
<Column0>John </Column0>
</Row>
<Row>
<Column0>Max </Column0>
</Row>
</rowset>RSXS4_1true

请注意“RSXS4_1true”附加在“xml”中,因此我无法使用

xml.Row.each{ Row-> log.info "${Row.Column0.text()}"  }

遍历 xml 标签。

更准确地说,我想获取“John”和“Max”并将它们插入某个表中。 欢迎任何帮助

最佳答案

因为您的数据在 CDATA block 中,所以它被视为字符串(然后需要重新解析,因为它是 XML)

// Parse the xml
def xml =  new XmlSlurper().parseText(response)

// Get the cdata text
def cdata = xml.Body.executeXMLQueryResult.return.rowset.text()

// Re-parse it
def innerXml = new XmlSlurper().parseText(cdata)

// Then iterate the rows
innerXml.Row.each { row ->
    println row.Column0.text()
}

关于database - 无法正确循环 groovy 中的 XML 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43328952/

相关文章:

mysql - 在一个查询中对多个数据库运行相同的查询 (MySQL)

java - Jenkins 进程内脚本审批

xml - 使用 groovy 更改 SoapUI 请求

groovy - 从: to: in Gradle script申请施工

soap - NiFi 如何使用带有 SOAP 的 InvokeHTTP 处理器

c# - SOAPUI 未显示来自 WSDL 的操作

mysql - mysql中子查询join语句的高效写法

javascript - 具有多个 Mongo DB 的 Meteor

Mysql Select with select result in another table

java - Grails 项目中的 ClassCastException