问题
when a xml message define like below, karate adds empty namespace to child element.
Karate feature
Feature: test xml
Scenario: test xml empty namespace
* def x =
"""
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<validateEmailAddressRequest xmlns="anotherUri">
<request>
<email>some@domain.com</email>
</request>
</validateEmailAddressRequest>
</soapenv:Body>
</soapenv:Envelope>
"""
* print x
Output
16:39:17.009 [main] INFO com.intuit.karate - [print] <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<validateEmailAddressRequest xmlns="anotherUri">
<request xmlns="">
<email>some@domain.com</email>
</request>
</validateEmailAddressRequest>
</soapenv:Body>
</soapenv:Envelope>HTML report: (paste into browser to view) | Karate version: 0.9.4
if you look at the <request>
element in the output it's now has the empty namespace where in feature does not.
That does create a problem when SOAP request hitting the server.
Do you know why this behaviour and how can I override it?
回答1:
This is very interesting and I just tried this and don't see this problem at all. My guess is that the version of the Java runtime you are using may have some bug in the XML libraries. Can you do us a favor and replicate this problem using this process ? https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue - and make sure you specify the exact OS + Java version.
Meanwhile as a workaround, you can do this - convert the XML to a string, do a Java String.replace() and then re-convert:
* xmlstring x = x
* xml x = x.replace(' xmlns=""', '')
* print x
来源:https://stackoverflow.com/questions/57042497/karate-xml-element-changed-to-have-empty-namespace