简体   繁体   English

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

[英]Azure Logic App - xpath for xml with namespace prefix

In my logic app i am using xpath() function to get the value of.在我的逻辑应用程序中,我使用 xpath() function 来获取的值。 I have tried different xpaths but getting error我尝试了不同的 xpath 但出现错误

'The template language function 'xpath' parameters are invalid: the 'xpath' parameter must be a supported, well formed XPath expression. '模板语言 function 'xpath' 参数无效:'xpath' 参数必须是受支持的、格式正确的 XPath 表达式。 Please see https://aka.ms/logicexpressions#xpath for usage details.'.请参阅https://aka.ms/logicexpressions#xpath了解使用详情。'。

i have the following xml:我有以下 xml:

在此处输入图像描述

I have tried:我努力了:

@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/\"])')

but getting the same error但得到同样的错误在此处输入图像描述

您可以使用以下表达式在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/\"]')

我做了Johns-305的建议。

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

Coming to this late, but the error is because you've escaped the double-quotes in the designer (which automagically escapes double-quotes for you).来晚了,但错误是因为你已经在设计器中转义了双引号(它会自动为你转义双引号)。

This is from the Reference guide to expression functions for Azure Logic Apps and Power Automate :这是来自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:如果您在代码视图中工作,请使用反斜杠字符 ( \ ) 转义双引号 ( " )。例如,将表达式序列化为 JSON 字符串时需要使用转义字符。但是,如果您在工作在逻辑应用设计器或表达式编辑器中,您不需要转义双引号,因为反斜杠字符会自动添加到基础定义中,例如:

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

Expression editor: xpath(xml(body('Http')), '/*[name()="file"]/*[name()="location"]')表达式编辑器: xpath(xml(body('Http')), '/*[name()="file"]/*[name()="location"]')

You might be better off converting to JSON and working with the data in that format. 您最好转换为JSON并使用该格式的数据。 At least you can get rid of all the silly namespace complexities that way. 至少您可以通过这种方式摆脱所有愚蠢的名称空间的复杂性。

LogicApps is JSON focused internally so doing so would be slightly more 'correct' anyway. LogicApps在内部关注JSON,因此无论如何这样做都会更加“正确”。

You can find samples at: JSONPath - XPath for JSON 您可以在以下位置找到示例: JSONPath-XPath for JSON

And an evaluator: JSONPath Online Evaluator 和评估者: JSONPath在线评估者

If what you need is the value of one of the internal nodes, you can try: 如果您需要的是内部节点之一的值,则可以尝试:

@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\"])')

I hope this points you in the right direction 我希望这可以为您指明正确的方向

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM