cancel
Showing results for 
Search instead for 
Did you mean: 

How to Convert complex XML nested structure into CSV in CPI using groovy

04-02-2023 6:18 AM
abbasabbas Discoverer
2567 views 5 comments
0 Likes
SAP Managed Tags
Subscribe
My Input Structure
<?xml version="1.0" encoding="utf-8"?>
<Root>
	<Headers>
		<HDR>3456</HDR>
		<Marble>Black</Marble>
        </Headers>
        <Detail>
		<Load>250kg</Load>
		<Size>44</Size>
        </Detail>
        <Trailer>
		<Print>A1</Print>
		<ID>W234</ID>
        </Trailer>

</Root>


My Outpuut Should look like below 3456;Black 250kg;44 A1;W234 Anyone has any input please share with the code to achieve above Requirement.
0 Likes

Accepted Solutions (0)

Answers (2)

Answers (2)

MortenWittrock
SAP Mentor
SAP Mentor

Hi Zaheer

You have a couple of options here:

  • Use Message Mapping to create an intermediate format that can be consumed by the XML To CSV Converter
  • Use XSLT to directly generate the CSV
  • Generate the CSV using a script

However, if your input document is as short as you show here, you can simply generate the whole thing in a single Content Modifier that extracts the values using XPath and generates the CSV payload:

Here's the body expression:

${property.HDR};${property.Marble}
${property.Load};${property.Size}
${property.Print};${property.ID}

Regards,

Morten

Former Member
0 Likes

Hi Zaheer

Did you use XmlUtil.serialize option

Here is a good documentation I found pl check and review if this works?

https://gist.github.com/magnuspalmer/12280bce85dc702714cf

Regards

Vinita

abbasabbas
Discoverer
0 Likes

Hi Vinita ,

The link shows CSV to xml requirement. I need to get CSV flat file as an Output, For my XML Input in CPI.

Could you please help achieving this ?