Xpath 导致空变量

Xpath results in empty variable

我对 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>some@address.com</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"/>

我在这里错过了什么?

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

对付它们的一种方法是在可能的情况下忽略它们;反过来,这可以通过使用 xpath 的 local-name() 函数来完成。

或者,在这种情况下:

//*[local-name()='Waybill']