2015-11-13 35 views
1

我想要使用xpath表達式,以便讀取下面給出的xml文件中的requestId字段。但是,此表達式不會導致匹配。當我嘗試用單引號括住字段名稱時,會導致編譯錯誤。我甚至嘗試在xpath表達式中使用本地名稱而不是名稱。我需要能夠獲得requestId字段的值,如圖所示。春季集成xpath命名空間問題

<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> 
+0

這一個重複在http://stackoverflow.com/questions/33697148/how-to-reference-an-existing-xpath-expression –

+0

謝謝@ArtemBilan ..我刪除了另一個,並編輯這一個。 – user1736333

回答

1

它的工作對我來說是這樣的:

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

,請注意逃脫"符號。

關於<int-xml:xpath-expression>

您也可以在filename-generator-expression中使用它,但是您應該按照XPathExpression進行操作,因此需要手動使用XmlPayloadConverter。然後在自定義bean的某個地方做這件事。

+0

這工作thx ..後續問題 - 我需要連接此xpath結果與屬性文件中的值。我會怎麼做? – user1736333

+0

'#xpath(payload,'// * [local-name()= " requestID "]')+'$ {my.property}'' –

+0

awesome that worked。感謝您的語法。 – user1736333