Translate

New Live Courses

🚀 *Gen AI Engineer Telugu (Production Focused)*
🗓️ *Date:* 30th Sept 2026, 07:00AM IST
📝 *Register Now!:*
https://www.vlrt.in/gr
👥 *Join WA Community:*
https://www.vlrt.in/gw
💡*Course Content:*
https://www.vlrt.in/ai
▶️ *Demo Videos:*
https://www.vlrt.in/gv

🚀 *Service now Admin/ Development (ITSM)FREE Demo in Telugu*
🗓️ *Date:* 30th Sept 2026, 08:00AM IST
📝 *Register Now!:*
https://www.vlrt.in/7r
👥 *Join WA Community:*
https://www.vlrt.in/7w
💡*Course Content:*
https://www.vlrt.in/7c
▶️ *Demo Videos:*
https://www.vlrt.in/7v

🚀 *Vulnerability Management Training Demo*
🗓️ *Date:* 30th Sept 2026, 09:00 AM IST
📝*Register Now!:*
https://www.vlrt.in/vr
👥 *Join Community:*
https://www.vlrt.in/cw
💡 *Course Content:*
https://www.vlrt.in/vc
▶️ *Demo Videos:*
https://www.vlrt.in/Vm

Tuesday, 12 March 2024

How to access attribute in xml payload?111

 How to access attribute in xml payload?


There are two primary ways to access attributes within an XML payload using DataWeave:

1. Using the @ symbol:

This is the most common approach for directly accessing an attribute's value based on its name.

Here's the syntax:



<elementName>@<attributeName>

Example:



%dw 2.0
---
name = message.customer@name
---

In this example, message.customer@name retrieves the value of the name attribute from the customer element within the message payload.

2. XPath expressions:

You can leverage XPath expressions for more complex scenarios, especially when dealing with nested elements or attributes with dynamic names.

Here's an example:



%dw 2.0
---
//book[@isbn="1234567890"]/@title
---

This expression searches for the book element with the isbn attribute value "1234567890" and then retrieves the value of the title attribute from that specific element.

Additional Points:

  • Ensure the namespace prefix is included if the attribute belongs to a different namespace than the element.

  • DataWeave offers other operators like .. for parent-child navigation and | for selecting multiple elements, which can be combined with the @ symbol for complex attribute access.

Here are some helpful resources for further exploration:

Remember:

  • DataWeave operates on a parsed XML structure. Ensure your payload is valid XML before attempting to access attributes.

  • Error handling mechanisms are recommended to gracefully handle situations where the expected element or attribute might not be present.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.