我想要使用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>
這一個重複在http://stackoverflow.com/questions/33697148/how-to-reference-an-existing-xpath-expression –
謝謝@ArtemBilan ..我刪除了另一個,並編輯這一個。 – user1736333