Loading

How to read xml payload as raw file along with encoding using XmlModule:: xpath query

Veröffentlichungsdatum: Mar 2, 2024
Aufgabe

GOAL

There are cases in which the input XML document contains special characters. This article describe how to read those xml payload along with encoding using XmlModule:: xpath query.
Schritte
Input XML Payload :
<?xml version="1.0"?>
<bookstore>
  <book category="cooking">
    <title lang="en">Everyday Italian</title>
    <author>Giada De &amp; Laurentiis</author>
    <year>2005</year>
    <price>30.00</price>
    <notes><![CDATA[
Please assign book review to Barnes & Nobel - 114-223-234
1. Please upload the sketch and photos as soon as possible after the initial visit. 
2. Please upload the initial report with 24 hours of initial on-site

Thank you]]></notes>
  </book>
</bookstore>
Use transformation message with following  syntax to read desired data using XPath expression

Method 1:  Payload as raw String with encoding
%dw 2.0
output application/java
---
XmlModule::xpath('bookstore/book/author/text()', payload.^raw as String {encoding: "ISO-8859-1"}, {})[0]
Method 2: Payload as raw String
%dw 2.0
output application/java
---
XmlModule::xpath('bookstore/book/author/text()', payload.^raw as String , {})[0]
Nummer des Knowledge-Artikels

001116607

 
Laden
Salesforce Help | Article