Layer 7 API Management

Expand all | Collapse all

why does xpath matches() not work?

Jump to Best Answer
  • 1.  why does xpath matches() not work?

    Posted 06-14-2018 10:18 AM

    When I use the xpath assertion with the function true(), it works fine, the result is obviously true.

    But when I want to use the function matches("abracadabra", "bra") as it is stated here XQuery 1.0 and XPath 2.0 Functions and Operators (SecondEdition)  (which also should return true), it always returns false, why?



  • 2.  Re: why does xpath matches() not work?

    Posted 06-15-2018 11:18 AM

    Hello,

     

    In the Evaluate XPath assertion change the XPath Version to 2.0 and it will succeed and return true



  • 3.  Re: why does xpath matches() not work?
    Best Answer

    Posted 06-18-2018 03:07 AM

    Hi,

     

     

    I already have the version set to 2.0, but I found out what the problem was: In my test case the response message was not set. So I manually added the following string to the response message:

     

    <?xml version="1.0" encoding="UTF-8"?>
    <a></a>

     

    After this, the xpath matched.



  • 4.  Re: why does xpath matches() not work?

    Posted 07-01-2018 08:27 PM

    Yes, the target message of xpath needs to be an xml message to make xpath work. Besides the default response, you can also use a context variable.