Loading
Salesforce から送信されるメールは、承認済ドメインからのみとなります続きを読む

How to work with special characters in XML using DataWeave

公開日: Mar 2, 2024
タスク

GOAL

This article will help you to work with special characters in XML in Dataweave. This will demonstrate how to pass a payload with the special characters in Dataweave, without escaping them.
ステップ
The Dataweave allows using the XML CDATA to pass special characters and white spaces in XML. 

CDATA is defined as blocks of text that are not parsed by the parser but are otherwise recognized as markup. For more details about CDATA please refer to "https://www.tutorialspoint.com/xml/xml_cdata_sections.htm"

Below is the XML input data :
{
"Example": "Sample\u008c\u0003Data"
}

After using the following Dataweave function:
%dw 2.0
output application/xml
---
a:{
"Example": payload.Example
}

The below-mentioned error will be observed due to the occurrence of white space:
"org.mule.weave.v2.exception.WriterExecutionException: Invalid white space character (0x3) in text to output (in xml 1.1, could output as a character entity), while writing Xml at . "
This is how the issue will look like:


User-added image


Use the following Dataweave code to read the above-mentioned input data:
%dw 2.0
output application/xml
---
a:{
"Example": payload.Example as CData
}

This will give a successful output as shown below:
<?xml version='1.0' encoding='UTF-8'?>
<a>
<Example><![CDATA[SampleŒData]]></Example>
</a>
 This is a successful output:
User-added image

 

ナレッジ記事番号

001116196

 
読み込み中
Salesforce Help | Article