cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Multi child xml to csv help required

bourner
New Contributor

HI,

I have an xml file that has multiple child arrays within it.

Iโ€™m struggling to get it into a flat format for export to csv, could someone spread a little snap love on this and help ๐Ÿ™‚

xml looks like this

<?xml version="1.0" encoding="utf-8"?>
	<FLEET>
		<ZMI_PM_S_OUTPUT_FLEET_LIST>
			<V_FLEET>
				<FLEET_NUM>SKBMI823EJ</FLEET_NUM>
				<EQUNR>000000000010014880</EQUNR>
				<ERDAT>2017-09-18</ERDAT>
				<ERNAM>DB21016</ERNAM>
				<EQASP>E</EQASP>
				<AEDAT>2021-10-01</AEDAT>
			</V_FLEET>
			<KSSK>
				<ZMI_PM_S_FLEET_LIST_KSSK>
					<KSSK_H>
						<OBJEK>000000000010014880</OBJEK>
						<MAFID>O</MAFID>
						<KLART>002</KLART>
						<CLINT>0000027802</CLINT>
						<ZAEHL>20</ZAEHL>
						<STATU>1</STATU>
					</KSSK_H>
					<AUSP>
						<API_VAL_R>
							<CHARACT>PM_ARB_A_BSTNR</CHARACT>
							<VALUE>10934902</VALUE>
						</API_VAL_R>
						<API_VAL_R>
							<CHARACT>PM_ARB_A_BSTPO</CHARACT>
							<VALUE>140</VALUE>
						</API_VAL_R>
					</AUSP>
				</ZMI_PM_S_FLEET_LIST_KSSK>
				<ZMI_PM_S_FLEET_LIST_KSSK>
					<KSSK_H>
						<OBJEK>000000000010014880</OBJEK>
						<MAFID>O</MAFID>
						<KLART>002</KLART>
						<CLINT>0000027803</CLINT>
						<ZAEHL>10</ZAEHL>
						<STATU>1</STATU>
					</KSSK_H>
					<AUSP>
						<API_VAL_R>
							<CHARACT>PM_ARB_A_AC_MAN</CHARACT>
							<VALUE>WEBASTO ATHEMIA</VALUE>
						</API_VAL_R>
						<API_VAL_R>
							<CHARACT>PM_ARB_A_ADVERT_FRAMES</CHARACT>
							<VALUE>No</VALUE>
						</API_VAL_R>
						<API_VAL_R>
							<CHARACT>PM_ARB_A_CCTV</CHARACT>
							<VALUE>No</VALUE>
						</API_VAL_R>
						<API_VAL_R>
							<CHARACT>PM_ARB_A_CURRENT_REG_DT</CHARACT>
							<VALUE>26.01.2017</VALUE>
						</API_VAL_R>
						<API_VAL_R>
							<CHARACT>PM_ARB_A_EMISSIONS</CHARACT>
							<VALUE>16.08.2019</VALUE>
						</API_VAL_R>
						<API_VAL_R>
							<CHARACT>PM_ARB_A_ENG_EURO_NORM</CHARACT>
							<VALUE>EURO VI</VALUE>
						</API_VAL_R>
						<API_VAL_R>
							<CHARACT>PM_ARB_A_GPS</CHARACT>
							<VALUE>No</VALUE>
						</API_VAL_R>
						<API_VAL_R>
							<CHARACT>PM_ARB_A_MAN_DT</CHARACT>
							<VALUE>26.01.2017</VALUE>
						</API_VAL_R>
					</AUSP>
				</ZMI_PM_S_FLEET_LIST_KSSK>
			</KSSK>
		</ZMI_PM_S_OUTPUT_FLEET_LIST>
	</FLEET>

if it helps โ€œOBJEKโ€ in <KSSK_H> is related to โ€œEQUNRโ€ in <V_FLEET>

Many thanks

10 REPLIES 10

darshthakkar
Valued Contributor

Hi @bourner,

Did you try using a JSON splitter already?

Hi Yes,

Iโ€™ve tried a JSON splitter.

Iโ€™ve tried to flatten both parts and then join them together. The V_Fleet xml element/objects are easy enough,

the KSSK part Iโ€™m unable to flatten

Thanks

robin
Former Employee

Try this pipeline (I donโ€™t know what kind of CSV you want but it may be a start).

image

12465_xml-to-flatten-csv_2022_05_19.slp (12.3 KB)

Iโ€™m using two JSON Splitters here:

image

and

image

The Mapper has basic flattening rules:

image

Youโ€™ll end up with an output that looks like this:

image

bourner
New Contributor

Thatโ€™s great,

I have a slight problem in that the actual xml also had some additional levels

<asx:abap version=โ€œ1.0โ€ xmlns:asx=โ€œABAP Developmentโ€>
asx:values

Example xml here

</asx:values>

</asx:abap>

As soon as I use this xml it fails. Could you possibly point me in the right direction, and possibly explain what itโ€™s doing ?

Apologies, Iโ€™m new to SL.

Thanks