我能够通过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 块中,所以它被视为字符串(然后需要重新解析,因为它是 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()
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)