Over a million developers have joined DZone.

Mule Dynamic Namespace

Learn more about namespaces in Mule with this look at XMLs with dynamice namespaces.

Is iPaaS solving the right problems? Not knowing the fundamental difference between iPaaS and dPaaS could cost you down the road. Brought to you in partnership with Liaison Technologies.

We often have a requirement of extracting values from nodes of complex XML. We use XPATH3 in our Mule expression to extract different values from different nodes. For the complex XMLs that have a namespace, we use Mule Namespace Manager to set the namespaces in the application.

But what if we have an XML that has dynamic namespace with it??

For example, let’s consider we have an XML with the following namespaces http://www.efg.com/schemas:

Image title

And the we have the same XML with the following namespaces http://www.axyz.com/schemas:

Image title

We can see here the same XML has dynamic namespaces http://www.efg.com/schemas and http://www.axyz.com/schemas

So, how can we set our flow such that we can extract the node values from the XML different and dynamic namespaces for the same XML???

Extracting Node Value From XML With Dynamic Namespaces:

Image title

Designing our Mule Flow:

Image title

We can see above that we have set the namespace manager and set both the namespaces there.
We can also see that in our XPATH3 we have used /* to get the value no matter what namespace is set in the XML out of both in the XML.

Our flows look as the above with a graphical view. We have used a logger to get the extracted value using XPATH3:

Image title

Testing Our Application
Image title

Let us consider, we get the above XML as input with the namespace shown above.
When we hit the URL http://localhost:7393/account, we successfully able to extract the value from the nodes in the console using logger with the namespace http://www.axyz.com/schemas.
Image title

For the following XML request:
Image title

Now if we change the namespace in the XML as http://www.efg.com/schemas and
we hit the URL http://localhost:7393/account again, we successfully able to extract the same value from the nodes in the console using logger as below:

Image title

Conclusion…

Here it was a small demonstration of using Namespace Manager with XPATH3 dynamically. We can set any number of namespace here as long the XML structure remains same.

Hope you like this article demonstrating extracting XML node values with dynamic namespaces. Now it's your turn to experiment and provide your feedback on the comments section.

Discover the unprecedented possibilities and challenges, created by today’s fast paced data climate and why your current integration solution is not enough, brought to you in partnership with Liaison Technologies.

Topics:
mule ,mule esb ,xml

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}