【发布时间】:2022-07-08 18:30:39
【问题描述】:
我的肥皂回应:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetInventoriesResponse xmlns="http://xxx">
<GetInventoriesResult>
<NewDataSet xmlns="">
<Inventory attr1="1" attr2="101" />
<Inventory attr1="1" attr2="101" />
</NewDataSet>
</GetInventoriesResult>
</GetInventoriesResponse>
</soap:Body>
</soap:Envelope>
我想从 //Inventory[0] 读取 attr1 的值
我正在做的是
import groovy.sql.Sql
import java.sql.DriverManager
import java.sql.Connection
import javax.sql.DataSource
import java.sql.Driver;
import java.util.*;
import java.text.*;
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def responseHolder = groovyUtils.getXmlHolder( messageExchange.responseContent )
responseHolder.namespaces['ns4']='http://xxx'
def CounGetInventoriesResponse=responseHolder["count(//Inventory)"]
def CompanyId=responseHolder.getNodeValue("//namf:Inventory[0]/@attr1")
log.info "att1"+CompanyId
companyid 的值显示为 null
我该如何解决这个问题。这里缺少什么
【问题讨论】:
-
我在您的 xml 中没有看到
CompanyId属性 -
更新了xml
-
你的问题是关于
xpath。您的 groovy 代码没有问题。最好删除groovy标签并添加xml和xpath标签 - 这样您可以获得更多关于您的实际问题的答案。