Forum Discussion

AdiSoap123's avatar
AdiSoap123
Occasional Contributor
13 years ago

Help with xpath assertion please

Hi,

I am not very technically inclined so excuse me for the basic question.

I am trying to get an assertion working with an xpath and getting nowhere. I have the below xml message and want to use the bold text as me assertion:

<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:Header>
<SyncovaSoapHeader xmlns="http://syncova.com/optima/webservices">
<AuthenticationString>?</AuthenticationString>
</SyncovaSoapHeader>
</soap:Header>
<soap:Body>
<GetTaskStatusResponse xmlns="http://syncova.com/optima/webservices">
[b]<GetTaskStatusResult>Failed</GetTaskStatusResult>[/b]
</GetTaskStatusResponse>
</soap:Body>
</soap:Envelope>


I have come up with the below:

declare namespace xmlns="http://syncova.com/optima/webservices"
/soap:Envelope/soap:Body/GetTaskStatusResponse/GetTaskStatusResult


But when I click "Select from current" I get an "Invalid XPath expression" error.

Running the text script gives the below error:

XPathContains assertion failed for path [declare namespace xmlns="http://syncova.com/optima/webservices"
/soap:Envelope/soap:Body/GetTaskStatusResponse/GetTaskStatusResult] : RuntimeException:net.sf.saxon.trans.XPathException: XPath syntax error at char 15 on line 2 in {\n/soap:Envelope/soap:Body}:
Prefix soap has not been declared


Anybody have any ideas?

3 Replies

  • tjdurden's avatar
    tjdurden
    Frequent Contributor
    Hi,

    For your XPath expression, try:

    //*[name() = 'GetTaskStatusResult'] 

    or

    declare namespace xmlns=" http://syncova.com/optima/webservices " 
    //xmlns:GetTaskStatusResult

    When the namespace changes, it generally causes headaches.
    In both cases, the "//" performs a search through nodes to find a match, rather than building up from root elements (/)

    If you've omitted a whole ton of XML for the sake of providing an example, let me know and I'll try and figure out something more specific.

    Kind regards,
    Tim