2017-12-01 2 views
1

Ich habe eine Anforderung, eine Ruhe-API aufzurufen, die die folgende XML-Antwort gibt. Ich möchte das Feld 'EntryID' nur mit Xpath extrahieren. Kann mir bitte jemand mit dem xpath-Ausdruck helfen und welchen Transformer ich nach dem HTTP-Outbound verwenden muss. Ich benutze Mule 3.5.0 Version.Xpath-Ausdruck in Mule

Eingangs 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> 

Mule Strömungs

<?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.

Antwort

1

Da Sie Mule 3.5-Laufzeit verwenden Sie folgendermaßen Ergebnisse zu erhalten

Platz Mule-Namespace-Manager Weltweit verwenden können:

<mulexml:namespace-manager includeConfigNamespaces="true"> 
     <mulexml:namespace prefix="v1" uri="http://www.w3.org/2005/Atom"/> 
</mulexml:namespace-manager> 

Stellen Sie sicher, Namespace für Namespace-Manager hinzufügen:

<mule xmlns="http://www.mulesoft.org/schema/mule/core" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" 
     xsi:schemaLocation=" 
      http://www.mulesoft.org/schema/mule/xml 
      http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd 
      http://www.mulesoft.org/schema/mule/core 
      http://www.mulesoft.org/schema/mule/core/current/mule.xsd"> 

ref: https://docs.mulesoft.com/mule-user-guide/v/3.5/xml-namespaces

updted Sie können mit extrahieren folgenden XPATH:

<logger message="#[xpath('/v1:feed/v1:entry/v1:content/v1:Entry/v1:EntryID/text()').text]" level="INFO" doc:name="Logger"/>