Forum Discussion

NLange's avatar
NLange
Occasional Contributor
13 years ago

[Resolved] Parse XML

Hello,

I am having some trouble parsing a XML Soap response. I have the following response from a SOAP request.

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<GetActiveSessionIdsResponse xmlns="urn:schemas-pelco-com:service:VideoOutput:1">
<sessionIds xmlns="">
<session>df126298-d6f7-49d3-bb4e-b854f297a84d</session>
<session>1e96e7bf-f50f-4c3c-8423-e77c46d9e688</session>
</sessionIds>
</GetActiveSessionIdsResponse>
</s:Body>
</s:Envelope>


I am using the following groovy code to extract the values between the <session></session> tags.
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( "GetActiveSessionIds#Response" )

def sessions = holder['(//ns1:GetActiveSessionIdsResponse[1]/sessionIds[1]/session[2]/text())']

log.info sessions


I get the following in the log.
Tue Oct 30 13:57:05 PDT 2012:INFO:[Ljava.lang.String;@10b1044


Am I forgetting to declare something?

Thanks in advance for the assistance.
  • RJanecek's avatar
    RJanecek
    Regular Contributor
    Try this:

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )

    def response = context.expand( '${GetActiveSessionIds#Response}' )
    def holderResponse = groovyUtils.getXmlHolder( response )

    def sessions = holderResponse.getNodeValue( "//*[local-name()='session'][2]")