Azure 逻辑应用程序 - xml 的 xpath,带有命名空间前缀

Azure Logic App - xpath for xml with namespace prefix

在我的逻辑应用程序中,我使用 xpath() 函数来获取 .我尝试了不同的 xpath 但出现错误

'模板语言函数 'xpath' 参数无效:'xpath' 参数必须是受支持的、格式正确的 XPath 表达式。请参阅 https://aka.ms/logicexpressions#xpath 了解使用详情。'.

我有以下 xml:

我试过:

@xpath(xml(<YourMessage>), '/*[local-name()=\"Envelope\" and namespace-uri()=\"http://schemas.xmlsoap.org/soap/envelope/\"]/*[local-name()=\"Body\" and namespace-uri()=\"http://schemas.xmlsoap.org/soap/envelope/\"]')
@xpath(xml(<YourMessage>), 'string(/*[local-name()=\"Envelope\" and namespace-uri()=\"http://schemas.xmlsoap.org/soap/envelope/\"]/*[local-name()=\"Body\" and namespace-uri()=\"http://schemas.xmlsoap.org/soap/envelope/\"])')

但得到同样的错误

您可以使用以下表达式在您的 xpath 中包含命名空间:

@xpath(YOURBODY, '/*[local-name()=\"Envelope\" and namespace-uri()=\"http://schemas.xmlsoap.org/soap/envelope/\"]/*[local-name()=\"Body\" and namespace-uri()=\"http://schemas.xmlsoap.org/soap/envelope/\"]')

您最好转换为 JSON 并使用该格式的数据。至少你可以通过这种方式摆脱所有愚蠢的命名空间复杂性。

LogicApps JSON 专注于内部,所以无论如何这样做 'correct' 会稍微多一些。

您可以在以下位置找到样本:JSONPath - XPath for JSON

还有一个评价者:JSONPath Online Evaluator

如果你需要的是其中一个内部节点的值,你可以尝试:

@xpath(<YourMessage>, 'string(/*[local-name()=\"Envelope\" and namespace-uri()=\"http://schemas.xmlsoap.org/soap/envelope/\"]/*[local-name()=\"Body\" and namespace-uri()=\"http://schemas.xmlsoap.org/soap/envelope/\"]/*[name()=\"SearchByABNv201408Response\"]/*[name()=\"ABRPayloadSearchResults\"]/*[name()=\"Request\"]/*[name()=\"identifierSearchRequest\"]/*[name()=\"authenticationGUID\"])')

希望这能为您指明正确的方向

我按照 Johns-305 的建议做了。

json(<Output>)['soap:Envelope']['soap:Body']

来晚了,但错误是因为您在设计器中转义了 double-quotes(它会自动为您转义 double-quotes)。

这是来自 Reference guide to expression functions for Azure Logic Apps and Power Automate:

Important

If you work in code view, escape the double quotation mark (") by using the backslash character (\). For example, you need to use escape characters when you serialize an expression as a JSON string. However, if you're work in the Logic App Designer or expression editor, you don't need to escape the double quotation mark because the backslash character is added automatically to the underlying definition, for example:

Code view: xpath(xml(body('Http')), '/*[name()=\"file\"]/*[name()=\"location\"]')

Expression editor: xpath(xml(body('Http')), '/*[name()="file"]/*[name()="location"]')