X路径的结果是空变量

问题描述 投票:0回答:1

我对WSO2 Micro intergator套件中的属性调解器非常困惑。有一个字段,我需要使用Xpath提取,然后发送到AWS SQS。以下是我试图提取该字段的文档(注意,我裁剪了文档的下半部分)。

<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope
    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
        <Waybill
            xmlns="urn:oasis:names:specification:ubl:schema:xsd:Waybill-2"
            xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
            xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
            xmlns:eba="http://ns.tln.nl/eba/schemas/1-0/"
            xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Waybill-2 http://docs.oasis-open.org/ubl/prd1-UBL-2.1/xsd/maindoc/UBL-Waybill-2.1.xsd http://ns.tln.nl/eba/schemas/1-0-1/EBA-Extensions.xsd">
            <ext:UBLExtensions>
                <ext:UBLExtension>
                    <ext:ExtensionContent>
                        <eba:ReplyAddress>
                            <eba:Webservice>
                                <eba:WebserviceEndPoint>http://www.google.com
                                </eba:WebserviceEndPoint>
                                <eba:Username>123</eba:Username>
                                <eba:Password>123
                                </eba:Password>
                            </eba:Webservice>
                        </eba:ReplyAddress>
                    </ext:ExtensionContent>
                </ext:UBLExtension>
                <ext:UBLExtension>
                    <ext:ExtensionContent>
                        <eba:ReplyAddress>
                            <eba:EmailAddress>[email protected]</eba:EmailAddress>
                        </eba:ReplyAddress>
                    </ext:ExtensionContent>
                </ext:UBLExtension>
            </ext:UBLExtensions>

我想解析 "Waybill "部分。无论我如何尝试使用该属性,结果要么是一个错误(语法),要么是一个空结果。

到目前为止,我试过的非工作代码的例子。

<property expression="//s:Body/Waybill" name="wayb" scope="default" type="STRING" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" />

<property expression="$:Body/Waybill" name="messageBody" scope="default" type="STRING" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="urn:oasis:names:specification:ubl:schema:xsd:Waybill-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:eba="http://ns.tln.nl/eba/schemas/1-0/" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Waybill-2 http://docs.oasis-open.org/ubl/prd1-UBL-2.1/xsd/maindoc/UBL-Waybill-2.1.xsd http://ns.tln.nl/eba/schemas/1-0-1/EBA-Extensions.xsd"/>

<property expression="//Waybill" name="messageBody" scope="default" type="STRING" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="urn:oasis:names:specification:ubl:schema:xsd:Waybill-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:eba="http://ns.tln.nl/eba/schemas/1-0/" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Waybill-2 http://docs.oasis-open.org/ubl/prd1-UBL-2.1/xsd/maindoc/UBL-Waybill-2.1.xsd http://ns.tln.nl/eba/schemas/1-0-1/EBA-Extensions.xsd"/>

<property expression="//Waybill" name="messageBody" scope="default" type="STRING" />

不过请注意,我可以很容易地抓取body字段,这确实有效。

<property expression="$body" name="messageBody" scope="default" type="STRING"/>

我到底漏了什么?

wso2 wso2esb wso2mi
1个回答
1
投票

这里的问题(就像许多xml片段的情况一样)是使用命名空间;正如专家们会告诉你的那样,它们是必要的--但在我看来,是必要的邪恶......。

处理它们的一种方法是尽可能地忽略它们;反过来,可以通过使用xpath的 local-name() 功能。

或者,在这种情况下,

//*[local-name()='Waybill']
© www.soinside.com 2019 - 2024. All rights reserved.