The DataWeave <~ Operator: How Angle Brackets in Customer Notes Broke 200 Orders
A customer typed "" in their notes field. It broke 200 XML orders and I spent 3 hours finding a one-line fix. TL;DR User-generated text with angle brackets (<, >) breaks XML output — the pars...

Source: DEV Community
A customer typed "" in their notes field. It broke 200 XML orders and I spent 3 hours finding a one-line fix. TL;DR User-generated text with angle brackets (<, >) breaks XML output — the parser treats them as tags The <~ metadata operator with {cdata: true} wraps content in CDATA sections CDATA preserves angle brackets as literal text: <![CDATA[text with <VIP>]]> The <~ operator requires DataWeave 2.5 (Mule 4.5+) JSON output silently ignores cdata metadata — no error, no effect The Problem: Valid JSON, Invalid XML We had a Mule flow converting customer orders from JSON to XML for an ERP. Worked for 6 months. Then 200 orders got rejected. The customer's notes field: { "customer": { "name": "Alice Chen", "email": "[email protected]", "notes": "Preferred customer since 2020 <VIP>" }, "orderId": "ORD-12345" } The DataWeave transform: %dw 2.0 output application/xml --- order @(id: payload.orderId): { customer @(class: "Person", source: "CRM"): { name: payload.c