我需要从soapui工具中获取xml的值并将这些数据存储到Excel工作表中。我在SoapUI工具中使用了groovy脚本。
如果Response有多个输出,这些输出存储在excel表中。就像LocationName和CustCity333Name有两次,所以这些输出应该存储到excel表中。请帮我解决这个问题
<script src="https://apis.google.com/js/platform.js" async defer></script>
<script>
var redirectUri = 'http://localhost:4200/list';
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
}
function signOut() {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
console.log('User signed out.');
});
}
</script>
答案 0 :(得分:0)
注意:
csv
格式。 rowId
进行标识。如果您不希望,可以删除。Groovy脚本
//Provide / edit file path for csv file in the below
def fileName = '/tmp/locationData.csv'
def xml = """<root xmlns:ns10='url1' xmlns:ns5='url2'> <ns10:Location>
<ns10:LocationId>
<ns5:RowId>7080013</ns5:RowId>
</ns10:LocationId>
<ns10:LocationDetails>
<ns10:AuditElement/>
<ns10:EffectiveDate/>
<ns10:LocationName>REMOVEDEPENDENCY004</ns10:LocationName>**
<ns10:RailIncData/>
<ns10:CustCity333Name>OAKLAND</ns10:CustCity333Name>**
<ns10:CustCity333Id>OAKLAND</ns10:CustCity333Id>
<ns10:CustCity333StateCode>TN</ns10:CustCity333StateCode>
<ns10:ParentCIFDetails/>
</ns10:LocationDetails>
</ns10:Location>
<ns10:Location>
<ns10:LocationId>
<ns5:RowId>7080018</ns5:RowId>
</ns10:LocationId>
<ns10:LocationDetails>
<ns10:AuditElement/>
<ns10:EffectiveDate/>
<ns10:LocationName>REMOVEDEPENDENCY004a</ns10:LocationName>**
<ns10:RailIncData/>
<ns10:CustCity333Name>OAKLAND1</ns10:CustCity333Name>**
<ns10:CustCity333Id>OAKLAND</ns10:CustCity333Id>
<ns10:CustCity333StateCode>TN</ns10:CustCity333StateCode>
<ns10:ParentCIFDetails/>
</ns10:LocationDetails>
</ns10:Location>
</root>"""
def parsedXml = new XmlSlurper().parseText(xml)
def data = parsedXml.'**'.findAll{ it.name() == 'Location'}.inject([]){list, loc -> list << new Expando(
rowId: loc?.LocationId?.RowId?.text(),
locationName: loc?.LocationDetails?.LocationName?.text(),
cityName: loc?.LocationDetails?.CustCity333Name?.text()); list }
if (0< data.size()) {
def sb = new StringBuffer(data[0].properties.keySet().join(',')).append('\n')
data.collect { sb.append(it.properties.values().join(',')).append('\n')}
new File(fileName).write(sb.toString())
} else {
println 'No records found'
}
您可以在线查看数据的快速生成方式 Demo