如何使用脚本断言提取CDATA?

时间:2014-06-14 12:37:17

标签: soapui

我收到以下回复:

<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">
   <soap:Body>
      <GetUKLocationByPostCodeResponse xmlns="http://www.webserviceX.NET">
         <GetUKLocationByPostCodeResult><![CDATA[<NewDataSet>
  <Table>
    <Town>Grangetown</Town>
    <County>Cardiff</County>
    <PostCode>CF1</PostCode>
  </Table>
  <Table>
    <Town>Leckwith</Town>
    <County>Vale of Glamorgan</County>
    <PostCode>CF1</PostCode>
  </Table>
  <Table>
    <Town>Canton</Town>
    <County>Cardiff</County>
    <PostCode>CF1</PostCode>
  </Table>
  <Table>
    <Town>Cardiff</Town>
    <County>Cardiff</County>
    <PostCode>CF1</PostCode>
  </Table>
</NewDataSet>]]></GetUKLocationByPostCodeResult>
      </GetUKLocationByPostCodeResponse>
   </soap:Body>
</soap:Envelope>

我可以使用属性转移提取Town,County,PostCode ..

但是,如何使用脚本断言提取相同内容..

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
log.info(groovyUtils)
def holder = groovyUtils.getXmlHolder("GetUKLocationByPostCode#ResponseAsXml")
log.info(holder)
def num = holder.getNodeValue("//Town")
log.info(num)

它返回了意外的元素cdata ..如何解决这个问题..?

1 个答案:

答案 0 :(得分:3)

我通过以下脚本实现了这一点:

import com.eviware.soapui.support.XmlHolder
responsexmlholder = new XmlHolder(messageExchange.getResponseContentAsXml())
responsexmlholder.declareNamespace("ns1","http://www.webserviceX.NET")
Cdataxml = responsexmlholder.getNodeValue("//ns1:GetUKLocationByPostCodeResult")
Cdataxmlholder = new XmlHolder(Cdataxml)
Town = Cdataxmlholder.getNodeValue("//Town")
相关问题