How can i use XPATH in mule for Getting the XML node values?

5.8k views Asked by At
#[xpath://soapenv:Envelope/soapenv:Body/out:notifications/out:Notification/out:sObject/urn:Summary] 

I am using the above XPATH Code for fetching the XML node values. It's not Working. How can Correct this. But the following code Working fine.

<logger message="#[xpath('//*[local-name()=\'Description\']').text]&quot;" level="INFO" doc:name="Logger"/> 

i want to work on with the 1st XPATH Syntax format How can i do this? The Following Code is my XML Dummy data.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:out="http://soap.sforce.com/2005/09/outbound" xmlns:urn="urn:sobject.enterprise.soap.sforce.com">
   <soapenv:Header/>
   <soapenv:Body>
      <out:notifications>
         <out:OrganizationId>12345</out:OrganizationId>
         <out:ActionId>999999</out:ActionId>
         <out:SessionId>000000</out:SessionId>
         <out:EnterpriseUrl>ggggggg</out:EnterpriseUrl>
         <out:PartnerUrl>hhhhhhh</out:PartnerUrl>
         <!--1 to 100 repetitions:-->
         <out:Notification>
            <out:Id>iiiiiiii</out:Id>
            <out:sObject>
               <!--Zero or more repetitions:-->
               <urn:fieldsToNull>jjjjjjj</urn:fieldsToNull>
               <urn:Id>789076</urn:Id>
               <!--Optional:-->
               <urn:FirstName>aaaa</urn:FirstName>
               <!--Optional:-->
               <urn:LastName>bbbbb</urn:LastName>
            </out:sObject>
         </out:Notification>
      </out:notifications>
   </soapenv:Body>
</soapenv:Envelope>
1

There are 1 answers

0
Seba On BEST ANSWER

First of all, in the first expression you're referring to an element called Summary which doesn't exist in your XML.

Now if you want to use namespaces in your xpath expression, you will have to declare them in the global element called namespace-manager:

<mulexml:namespace-manager includeConfigNamespaces="false">
    <mulexml:namespace prefix="soapenv" uri="http://schemas.xmlsoap.org/soap/envelope/" />
    <mulexml:namespace prefix="out" uri="http://soap.sforce.com/2005/09/outbound" />
    <mulexml:namespace prefix="urn" uri="urn:sobject.enterprise.soap.sforce.com" />
</mulexml:namespace-manager>

Using the above and replacing Summary with something that does exist, works:

<logger level="WARN" message="#[xpath://soapenv:Envelope/soapenv:Body/out:notifications/out:Notification/out:sObject/urn:Id]" />