我有一个返回给我的xml有效负载
<response><row><row _id="1" _uuid="CD07C40E-4943-44B0-BF5E-370DA2133E25" _position="1"
_address="http://data.seattle.gov/resource/fire-911/1"><type> --T::00</type></row><row _id="111"
_uuid="2423EC44-56D5-494C-941F-6F3B5DF49AC5" _position="111"
_address="http://data.seattle.gov/resource/fire-911/111"><address>10049 College Way N</address>
<type>Aid Response</type><latitude>47.701756</latitude><longitude>-122.335022</longitude>
<report_location latitude="47.701756" longitude="-122.335022"/>
<incident_number>F110104009</incident_number></row>
我想用xpath捕获“行”节点:#[xpath://response/row/row]
。这会返回一串逗号[, , , , , , , ,]
而不是
<row _id="111" _uuid="2423EC44-56D5-494C-941F-6F3B5DF49AC5" _position="111" _address="http://data.seattle.gov/resource/fire-911/111">
<address>10049 College Way N</address>
<type>Aid Response</type>
<latitude>47.701756</latitude>
<longitude>-122.335022</longitude>
<report_location latitude="47.701756" longitude="-122.335022"/>
<incident_number>F110104009</incident_number>
</row>
如果我通过在线测试程序插入此xpath,则可以://response/row/row
<row _id="112" _uuid="DDAE5717-4A07-4E71-9CAE-D1F1CBAA94FD" _position="112" _address="http://data.seattle.gov/resource/fire-911/112">
<address>5929 Beach Dr Sw</address>
<type>Aid Response</type>
<latitude>47.550431</latitude>
<longitude>-122.397816</longitude>
<report_location latitude="47.550431" longitude="-122.397816"/>
<incident_number>F110104008</incident_number>
</row>
我需要做些什么让它在骡子中工作?
我的configuration.xml:
<flow name="seattleemergencyFlow1" doc:name="seattleemergencyFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8900"
path="get-emergency" doc:name="HTTP"/>
<http:outbound-endpoint exchange-pattern="request-response" host="data.seattle.gov" port="80"
path="resource/kzjm-xkqj.xml?" method="GET" contentType="application/json" doc:name="HTTP"/>
<object-to-string-transformer doc:name="Object to String"/>
<logger message="#[xpath://response/row/row]" level="ERROR" doc:name="Logger"/>
谢谢!
答案 0 :(得分:0)
由于您使用的是Mule&gt; = 3.3.x,因此您应该使用MEL而不是旧的xpath:
表达式求值程序。
使用MEL:
如果您想获得java.util.List
org.dom4j.Element
,请使用:
#[xpath('//response/row/row')]
如果您只想要第一个org.dom4j.Element
,请使用:
#[xpath('//response/row/row')[0]]
如果您想获得此元素的java.lang.String
表示,请使用:
#[xpath('//response/row/row')[0].asXML()]