【问题标题】:Karate DSL: Extract XML attribute value from the response [duplicate]空手道 DSL:从响应中提取 XML 属性值 [重复]
【发布时间】:2021-03-11 13:00:51
【问题描述】:

我收到如下回复:

如何将属性xmlns的值提取为“https://www.w3schools.com/xml/”?

  • 默认响应 = """ 肥皂:身体 37.7777777777778 肥皂:身体> 信封> """

【问题讨论】:

    标签: karate


    【解决方案1】:

    有时最好转换为 JSON。试试这个例子:

    * def response =
    """
    <soap:Envelope xmlns:soap="schemas.xmlsoap.org/soap/envelope" xmlns:xsi="w3.org/2001/XMLSchema-instance" xmlns:xsd="w3.org/2001/XMLSchema"> <soap:Body> <FahrenheitToCelsiusResponse xmlns="w3schools.com/xml"> <FahrenheitToCelsiusResult>37.7777777777778</FahrenheitToCelsiusResult> </FahrenheitToCelsiusResponse> </soap:Body> </soap:Envelope>
    """
    * json response = response
    * def ns = response['soap:Envelope']['_']['soap:Body'].FahrenheitToCelsiusResponse['@'].xmlns
    * match ns == 'w3schools.com/xml'
    

    现在你可以得到任何你想要的属性了。

    另请阅读:https://github.com/intuit/karate#print - 特别是关于内部 XML 是 JSON 的部分,因此如果您没有正确打印,您将看不到您想要的内容。

    【讨论】:

    猜你喜欢
    • 2021-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-21
    相关资源
    最近更新 更多