這是我的源代碼xml示例。如何在Mule中從xml中提取節點值
<?xml version="1.0" encoding="UTF-8"?>
<XML>
<Meta>
<Status>Success</Status>
<Debug></Debug>
</Meta>
<Result>
<Surveys>
<element id='0'>
<responses>6</responses>
<SurveyType>SS</SurveyType>
<SurveyID>SV_01C7i5l62dnKTel</SurveyID>
<SurveyName>Georgia Dome GS</SurveyName>
<SurveyDescription>Georgia Dome</SurveyDescription>
<SurveyOwnerID>UR_8IZEh6bVlQaF41L</SurveyOwnerID>
<DivisionID>DV_2cmHYrtm8C93T6J</DivisionID>
<SurveyStatus>Active</SurveyStatus>
<SurveyStartDate>0000-00-00 00:00:00</SurveyStartDate>
<SurveyExpirationDate>0000-00-00 00:00:00</SurveyExpirationDate>
<SurveyCreationDate>2014-06-18 15:14:48</SurveyCreationDate>
<CreatorID>UR_8IZEh6bVlQaF41L</CreatorID>
<LastModified>2014-10-24 14:01:23</LastModified>
<LastActivated>2014-06-24 09:39:23</LastActivated>
<GroupName>Analytics</GroupName>
<GroupID>GR_3kMZEX6m1IqqSjP</GroupID>
<UserLastName>Parrott-Sheffer</UserLastName>
<UserFirstName>Brandon</UserFirstName>
</element>
我想打印所有進來的標籤值的列表 - <SurveyID>
。
以下是我的騾子流量:
</flow>
</flow>
<flow name="testFlow1" doc:name="testFlow1">
<file:inbound-endpoint path="C:\Data\Mule\deploy\out" responseTimeout="10000" doc:name="File"/>
<file:file-to-string-transformer doc:name="File to String"/>
<logger message="*********First Message - ********* #[message.payload.toString()]" level="ERROR" doc:name="Logger"/>
<foreach collection="#[xpath('//XML/Result/Surveys/element')]" doc:name="For Each">
<set-variable doc:name="Variable" value="#[xpath('SurveyID/text()').text]" variableName="id"/>
<logger level="INFO" message="********* The ID is - #[flowVars['id']]" doc:name="Logger"/>
</foreach>
</flow>
但我在控制檯上看到的結果是 -
INFO 2015年1月20日17:03:35527 [REST的API ] .testFlow1.stage1.02] org.mule.transformer.simple.AddFlowVariableTransformer:使用 「#[xpath('// SurveyID/text()')在 鍵」id「處找不到變量。 ]「。由於該值被標記爲可選,因此該變量的消息中沒有設置任何內容能夠
INFO 2015-01-2017:03:35527 [REST的API] .testFlow1.stage1.02] org.mule.api.processor.LoggerMessageProcessor:空
我正在從這個XML第三方,我注意到它沒有任何名稱空間信息。你能幫我修正我的xpath並顯示值。
我使用的騾子工作室3.5
的所有值爲什麼使用''//一個for-each循環裏面工作,也就是說,檢索正確的節點?出於好奇,我不認識騾子。 – 2015-01-21 10:45:06
foreach的''集合'中的xpath將提取元素集合,然後foreach將迭代每個元素。然後,'//'將從新的根元素收集,順便說就是''element'。 – 2015-01-21 11:29:57
你確定'for'中的'//'沒有檢索'element'的'_outside_'節點嗎?我知道每個其他的XPath實現都是這樣的。 – 2015-01-21 11:34:22