Azure 逻辑应用程序 xpath 不返回值

Azure Logic Apps xpath not returning value

我正在开发调用 SOAP 的逻辑应用程序 API。我正在尝试从 XML 响应中提取节点的值,但似乎无法获得可用于进一步操作的值输出。

这是XML回复的删节版:

<?xml version="1.0" encoding="utf-8"?>
<Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Body>
        <DoLoginResponse xmlns="http://apiserver.wireless.com/0905/">
            <DoLoginResult>
                <OperationStatus>true</OperationStatus>
                <StatusMessage />
                <SecurityProfile>
                    <User>
                        <UserID>6e37c720-b40e-4a4b-8e7a-b0c431ac8749</UserID>
                    </User>
                    <Session>
                        <SessionId>888c9c94-f33b-4766-97c0-8f8031bda104</SessionId>
                    </Session>
                </SecurityProfile>
                <Authenticated>true</Authenticated>
            </DoLoginResult>
        </DoLoginResponse>
    </Body>
</Envelope>

在逻辑应用程序设计器中,我想提取 AuthenticatedSessionID 节点。例如,我尝试使用 xpath 函数获取经过身份验证的节点值:

xpath(outputs('xml'),'/Envelope/Body/DoLoginResponse/DoLoginResult/Authenticated')

运行后输出为[]

作为使用 XML 的新手,我们将不胜感激。

我不熟悉 Azure 逻辑应用程序设计器,但 XPath 表达式的问题是 DoLoginResponse 节点的命名空间。有几种方法可以解决这个问题,但如果你真的只是想忽略命名空间,你可以使用如下表达式:

/Envelope/Body/*[local-name() = "DoLoginResponse"]/*[local-name() = "DoLoginResult"]/*[local-name() = "Authenticated"]/string()

Body/* selects Body的所有子节点。谓词 (local-name() = 'DoLoginResponse') 将该序列限制为仅具有本地节点名称 'DoLoginResponse' 的序列。等等。

如果你也想检查命名空间,你可以像这样扩展谓词:

[local-name() = "DoLoginResponse" and namespace-uri() = "http://apiserver.wireless.com/0905/"]

最后,您可能试图提取 Authenticated 的原子值而不是整个 Authenticated 节点。比如你只想select Authenticated 的内容为text/string,你可以这样做:

/Envelope/Body/*[local-name() = 'DoLoginResponse']/*[local-name() = 'DoLoginResult']/*[local-name() = 'Authenticated']/text()

由于我不熟悉您使用的API,您可能需要注意我这里示例中的引号。不确定是否需要转义。

文档元素的名称不是Envelope,而是http://schemas.xmlsoap.org/soap/envelope/:Envelope,如果您能够通过逻辑应用程序中的 NamespaceManager,你不能。是的,XPath 就是那么迂腐。命名空间在 XPath 中很重要。

为了使这更简单,您可以使用忽略元素名称空间的语法 /*[local-name() = 'Envelope']。或者,假设您希望在结构已知的 SOAP 消息中查询,将其进一步缩写为 /*,因为您知道文档元素将始终为 soap:Envelope.

逻辑应用程序 不好 操纵 XML,如果有选择,我会使用函数或几乎任何其他东西。