spring集成xpath命名空间问题

时间:2015-11-13 02:39:38

标签: spring-integration

我正在尝试使用xpath表达式,以便在下面给出的xml文件中读取requestId字段。但是,这个表达式导致没有匹配。当我尝试用单引号括起字段名称时,会导致编译错误。我甚至尝试在xpath表达式中使用local-name而不是name。我需要能够获得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>

1 个答案:

答案 0 :(得分:1)

这对我有用:

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

注意转义的"符号。

关于<int-xml:xpath-expression>

您也可以在filename-generator-expression中使用它,但您应该使用XPathExpression,因此请手动使用XmlPayloadConverter。并在自定义bean的某个地方做这一切。