【问题标题】:xpath expression issue in mulemule 中的 xpath 表达式问题
【发布时间】:2014-10-04 10:09:37
【问题描述】:

我有一个返回给我的 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>

我需要做什么才能让它在 mule 中工作?

我的配置.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"/>

谢谢!

【问题讨论】:

  • 提示:在代码块前放四个空格以启用语法高亮。我尝试编辑您的问题,但您将其还原。
  • 你用的是什么Mule版本?
  • 嗨,David,我相信最新消息:Anypoint Studio - Mule ESB 工具 Anypoint Studio 2014 年 7 月发布版本 ID:201407311443
  • 我还在调查这个。我注意到您提供的 XML 示例无效:它最后缺少 &lt;/row&gt;&lt;/response&gt; 是有效的。是复制/粘贴问题还是您实际上正在处理损坏的 XML 输入(是的,这发生在 IRL :))

标签: xml xpath mule esb


【解决方案1】:

由于您使用的是 Mule >= 3.3.x,因此您应该使用 MEL 而不是旧的 xpath: 表达式评估器。

使用 MEL:

  • 如果您想获得java.util.Listorg.dom4j.Element,请使用:

    #[xpath('//response/row/row')]
    
  • 如果您只想要第一个 org.dom4j.Element,请使用:

    #[xpath('//response/row/row')[0]]
    
  • 如果您想获得此元素的 java.lang.String 表示,请使用:

    #[xpath('//response/row/row')[0].asXML()]
    

【讨论】:

    猜你喜欢
    • 2018-05-15
    • 2011-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-03
    • 1970-01-01
    • 2013-07-24
    • 2020-09-03
    相关资源
    最近更新 更多