【发布时间】:2018-05-15 04:12:47
【问题描述】:
我需要调用一个提供以下 xml 响应的 rest api。我只想使用 xpath 提取字段“EntryID”。有人可以帮我解决 xpath 表达式以及在 http 出站后我需要使用什么转换器。我使用的是 Mule 3.5.0 版本。
输入 XML
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<entry>
<author>
<name>teden</name>
</author>
<contributor>
<name>angelaw</name>
</contributor>
<content type="xhtml">
<Entry>
<EntryID>53339</EntryID>
</Entry>
</content>
</entry>
</feed>
骡流
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.5.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
<mulexml:namespace-manager
includeConfigNamespaces="true">
<mulexml:namespace prefix="v1"
uri="http://www.w3.org/2005/Atom" />
</mulexml:namespace-manager>
<mulexml:xml-to-dom-transformer name="Parse_XML"
doc:name="Parse XML Message" />
<flow name="testFlow">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="8081" path="test" doc:name="HTTP" />
<transformer ref="Parse_XML" doc:name="Transformer Reference" />
<expression-component doc:name="Expression"><![CDATA[flowVars.test= xpath('/v1:feed/entry/content/Entry/EntryID/text()').text;]]></expression-component>
<logger level="INFO" doc:name="Logger" />
</flow>
</mule>
TIA。
【问题讨论】: