У нас вы можете посмотреть бесплатно How to Convert JSON to XML with @ Attributes and Namespaces in DataWeave или скачать в максимальном доступном качестве, видео которое было загружено на ютуб. Для загрузки выберите вариант из формы ниже:
Если кнопки скачивания не
загрузились
НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если возникают проблемы со скачиванием видео, пожалуйста напишите в поддержку по адресу внизу
страницы.
Спасибо за использование сервиса ClipSaver.ru
Learn how to transform JSON properties prefixed with '@ ' into XML attributes using MuleSoft DataWeave 2.0, including handling namespaces and nested objects accurately. --- This video is based on the question https://stackoverflow.com/q/79515172/ asked by the user 'Zak01' ( https://stackoverflow.com/u/18032218/ ) and on the answer https://stackoverflow.com/a/79517031/ provided by the user 'Harshank Bansal' ( https://stackoverflow.com/u/10946202/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions. Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: JSON conversion to XML using attributes and namespaces Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l... The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license. If anything seems off to you, please feel free to drop me a comment under this video. --- Introduction When converting JSON to XML in MuleSoft's DataWeave, fields starting with @ in JSON are typically expected to become XML attributes rather than new XML tags. A common issue occurs when these fields instead become child elements with names like <@ id>...</@ id>, which is invalid XML. This guide explains how to properly transform JSON with @ -prefixed fields into XML attributes while preserving namespaces. Understanding XML Attributes in DataWeave In DataWeave 2.0, to assign attributes to an XML tag: [[See Video to Reveal this Text or Code Snippet]] The attribute map inside @ () must be a key-value pair, not a nested object. You cannot pass an object directly as an attribute; it must be deconstructed with extra parentheses: [[See Video to Reveal this Text or Code Snippet]] Solution: Recursively Convert @ -Prefixed Keys into Attributes We can create a recursive function to: Extract keys starting with @ and convert them into XML attributes (removing the @ prefix). Keep remaining keys as XML elements. Properly apply XML namespaces. Here's a concise DataWeave script implementing this: [[See Video to Reveal this Text or Code Snippet]] Explanation getAttributes extracts and renames @ keys to attribute names. getNonAttributes returns the rest of the object keys as XML elements. fromJsonToXml recursively applies these functions, building XML structure with attributes. Finally, the root element trans is explicitly namespaced with ns0 and given its attributes. Result The output matches the desired XML structure, with all @ fields correctly rendered as XML attributes, respecting namespaces: [[See Video to Reveal this Text or Code Snippet]] Summary When converting JSON to XML with DataWeave, prefix @ keys are not automatically attributes. Use custom logic to remove the prefix and assign as attributes using @ (), with deconstruction. Recursion handles nested JSON objects consistently. Apply namespaces by prefixing tags as ns0# tag. This method ensures your XML outputs are clean, valid, and semantically correct.