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

  • Why Spark Executors Leave Cores Idle on YARN: A Packing Model for Executor Sizing
  • PWA on iOS, Part 2: HTTPS, Manifest and Service Worker
  • Closing the Drift Loop: An AI Agent That Drafts Terraform Fixes
  • Genkit Flows as senro Steps: Extremely Powerful AI Pipelines in Go

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
·
Updated Feb. 26, 16 · Analysis
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
10.1K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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