spring 集成 xpath 命名空间问题

spring integration xpath namespace issue

我正在尝试使用 xpath 表达式,以便读取下面给出的 xml 文件中的 requestId 字段。但是,此表达式不会导致匹配。当我尝试用单引号将字段名称括起来时,会导致编译错误。我什至尝试在 xpath 表达式中使用本地名称而不是名称。我需要能够获得 requestId 字段的值,如图所示。

<int-file:outbound-channel-adapter
    id="file" mode="APPEND" charset="UTF-8"
    directory="C:\Users\dvenkat1\Desktop\test" 
    auto-create-directory="true"  filename-generator-expression="#xpath(payload, '/*[name()=Envelope]/*[name()=Body]/*[name()=processArchiveRequest]/*[name()=fulfillmentRequest]/*[name()=requestHeader]/*[name()=requestID]/text()')" />

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"        xmlns:sch="http://...schema">
     <soap:Header/>
     <soap:Body>
     <sch:processArchiveRequest>
          <sch:fulfillmentRequest>
              <sch:requestHeader>
                 <sch:requestID>Samplereq</sch:requestID>
             ............

另一种选择是使用这样的东西:

<int-file:outbound-channel-adapter
id="file" mode="APPEND" charset="UTF-8"
directory="C:\Users\dvenkat1\Desktop\test" 
auto-create-directory="true"  filename-generator-expression="#xpath(payload, 'reference exp1 here']) " />

  <int-xml:xpath-expression id = "exp1"               
  expression="name(/soapNs:Envelope/soapNs:Body/schNs:processArchiveRequest/schNs: fulfillmentRequest/schNs:requestDetail/*[1])" 
namespace-map="archiveNamespaceMap" /> 

<util:map id="archiveNamespaceMap">
    <entry key="soapNs" value="http://www.w3.org/2003/05/soap-envelope" />
    <entry key="schNs" value="http://blah../schema" />
</util:map>

它对我来说是这样的:

filename-generator-expression="#xpath(payload, '//*[local-name()=&quot;requestID&quot;]')"

注意转义的 " 符号。

关于 <int-xml:xpath-expression>

您也可以从 filename-generator-expression 使用它,但您应该遵循 XPathExpression 并因此手动使用 XmlPayloadConverter。并在自定义 bean 的某处执行所有操作。