DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • The Hidden Engineering Cost of XML in Enterprise Development Workflows
  • How to Convert XLS to XLSX in Java
  • Thread-Safety Pitfalls in XML Processing
  • Loading XML into MongoDB

Trending

  • Encryption Won't Survive Quantum Computing: What to Do?
  • AI Is Finding Bugs Faster Than Enterprises Can Patch — Here's What Data Security Teams Should Do
  • Building an Agentic Incident Resolution System for Developers
  • The Hidden Cost of AI-Generated Frontend Code
  1. DZone
  2. Coding
  3. Languages
  4. Mule Dynamic Namespace

Mule Dynamic Namespace

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

By 
Anirban Sen Chowdhary user avatar
Anirban Sen Chowdhary
·
Updated Feb. 26, 16 · Analysis
Likes (2)
Comment
Save
Tweet
Share
10.1K Views

Join the DZone community and get the full member experience.

Join For Free

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.

XML

Opinions expressed by DZone contributors are their own.

Related

  • The Hidden Engineering Cost of XML in Enterprise Development Workflows
  • How to Convert XLS to XLSX in Java
  • Thread-Safety Pitfalls in XML Processing
  • Loading XML into MongoDB

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook