回复是:
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Header>
<platformMsgs:documentInfo xmlns:platformMsgs="urn:messages_2014_2.platform.webservices.netsuite.com">
<platformMsgs:nsId>WEBSERVICES_TSTDRV1371590_041220151334115279325827527_fefe8c</platformMsgs:nsId>
</platformMsgs:documentInfo> </soapenv:Header> <soapenv:Body>
<addResponse xmlns="">
<platformMsgs:writeResponse xmlns:platformMsgs="urn:messages_2014_2.platform.webservices.netsuite.com">
<platformCore:status xmlns:platformCore="urn:core_2014_2.platform.webservices.netsuite.com" isSuccess="true"/>
<platformMsgs:baseRef xmlns:platformCore="urn:core_2014_2.platform.webservices.netsuite.com" internalId="5450" type="customer" xsi:type="platformCore:RecordRef"/>
</platformMsgs:writeResponse>
</addResponse>
</soapenv:Body>
</soapenv:Envelope>
如何使用groovy我的代码获取此xml的内部Id:
def slurper = new XmlSlurper()。parseText(response.text);
答案 0 :(得分:1)
你的意思是:
def slurper = new XmlSlurper().parseText(response.text);
def id = slurper.Body.addResponse.writeResponse.baseRef.@internalId
assert id == '5450'
答案 1 :(得分:0)
最简单的答案:
def slurper = new XmlSlurper().parseText(response.text)
def internalId = slurpXml['Body']['addResponse']['writeResponse']['baseRef'].attribute('internalId')
当然,这完全忽略了命名空间。不过,你不必在你的例子中担心它。