这是我的源代码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