Search code examples
xmlparsingheaderresponsekarate

Karate Response xml is not parsing and says not XML


I have a feature that returns response in xml format with

Response xml:

**Content-Type: application/xop+xml Content-Transfer-Encoding: binary

<soap:Envelope> <soap:Body> .. .. </soap:Body> </soap:Envelope>

when I try to read karate.xmlPath(response) karate throws error not XML or cannot convert

how shall i ignore the extra lines received in the response with Content-Type which is blocking karate to read as valid xml


Solution

  • Response xml:

    content-type: '---'
    content-transfer: '----'
    <soap:Envelope>----</soap:Envelope>
    

    Karate couldnt parse as it had characters and doesnt seem to be valid xml. Removed the unwanted characters using substring and converting back to xml fixed the issue

    Given path '/endpoint'
    And request requestpayload
    And method post
    Then status 200
    * xml removeUnwantedString = response.substring(100)
    * def parseResponse = karate.xmlPath(removeUnwantedString, 'Envelope/Body/column')
    

    it got fixed and i was able to process it