Mule Dynamic Namespace
Mule Dynamic Namespace
Learn more about namespaces in Mule with this look at XMLs with dynamice namespaces.
Join the DZone community and get the full member experience.Join For Free
How to Transform Your Business in the Digital Age: Learn how organizations are re-architecting their integration strategy with data-driven app integration for true digital transformation.
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:
And the we have the same XML with the following namespaces 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:
Designing our Mule Flow:
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:
Testing Our Application
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.
For the following XML request:
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:
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.
Opinions expressed by DZone contributors are their own.