Nehra An
Nehra An

Reputation: 91

Using xpath to extract an element out of nested xml document - SOAPUI

Hi below is the xml that I have:

<s:Fault>
 <faultcode  xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundat      ion/dispatcher">
a:InternalServiceFault
 </faultcode>
 <faultstring     xml:lang="en-NZ">**<![CDATA[<ns0:Root                       xmlns:ns0="http://NZPost.EAI.UnifiedTracking.Schemas.FaultMessage">
  <FaultCode>NZPUT004</FaultCode>
  <Reason>"**Object reference not set to an instance of an object.**"    </Reason>
  </ns0:Root>]]**>
 </faultstring>
 .
 .
 .
</s:fault>

I want to use assertion in SoapUI to confirm that the response contains the text "Object reference not set to an instance of an object". But I don't know the xpath that should be used in the declare segment to reach the Reason tag.

I am able to navigate to and in the above example but the moment I write faultString//FaultCode or faultString//Message it throws an error saying that there is no match in current response.

Please help!

Upvotes: 0

Views: 538

Answers (1)

Muhammad Hamed
Muhammad Hamed

Reputation: 1239

You can not navigate the xml content of the Cdata markup using the path but you can get it as a string.. so you can parse it by substring-after and substring-before methods or by regular expression

substring-before(substring-after(.//*[local-name()='faultstring'] , 'Reason&gt;') , '&lt;/Reason')

The result will be

"**Object reference not set to an instance of an object.**"

or

contains(.//*[local-name()='faultstring'] , '**Object reference not set to an instance of an object.**')

which will result

true

I hope this could help

Upvotes: 1

Related Questions