XML to CSV component
The XML to CSV component allows you to convert files in the XML format into the CSV format.
Configuration
The XML to CSV component has the following configuration options:
Include header
Specify whether to include a header row in the CSV output.
Options
Yes
(default)No
- XML Input
- CSV Output - Yes
- CSV Output - No
<?xml version="1.0" encoding="UTF-8"?>
<breakfast_menu>
<food>
<name>food1</name>
<price>1</price>
<description>desc1</description>
</food>
<food>
<name>food2</name>
<price>2</price>
<description>desc2</description>
</food>
<food>
<name>food3</name>
<price>3</price>
<description>desc3</description>
</food>
</breakfast_menu>
"name","price","description"
"food1","1","desc1"
"food2","2","desc2"
"food3","3","desc3"
"food1","1","desc1"
"food2","2","desc2"
"food3","3","desc3"
Include index column
Specify whether to include an index column in the CSV output.
Options
Yes
No
(default)
When enabled, the index column will always be the first column and line numbers will be unquoted.
- XML Input
- CSV Output - No
- CSV Output - Yes
<?xml version="1.0" encoding="UTF-8"?>
<breakfast_menu>
<food>
<name>food1</name>
<price>1</price>
<description>desc1</description>
</food>
<food>
<name>food2</name>
<price>2</price>
<description>desc2</description>
</food>
<food>
<name>food3</name>
<price>3</price>
<description>desc3</description>
</food>
</breakfast_menu>
"name","price","description"
"food1","1","desc1"
"food2","2","desc2"
"food3","3","desc3"
"line","name","price","description"
1,"food1","1","desc1"
2,"food2","2","desc2"
3,"food3","3","desc3"
Index column name
Specify the name of the index column. The default value is line
.
Only available when Include index column is enabled.
Delimiter
Specify the character used to separate column values in the CSV output. The default value is ,
(comma).
Line separator
Specify the character used to separate lines in the CSV output.
Options
Line Feed (\n)
(default)Carriage Return (\r)
End Of Line (\r\n)
Order headers
Specify how the columns should be ordered in the CSV output (by name).
Options
Original
(default)Ascending
Descending
- XML Input
- CSV Output- Original
- CSV Output- Ascending
- CSV Output- Descending
<?xml version="1.0" encoding="UTF-8"?>
<breakfast_menu>
<food>
<name>food1</name>
<price>1</price>
<description>desc1</description>
</food>
<food>
<name>food2</name>
<price>2</price>
<description>desc2</description>
</food>
<food>
<name>food3</name>
<price>3</price>
<description>desc3</description>
</food>
</breakfast_menu>
"name","price","description"
"food1","1","desc1"
"food2","2","desc2"
"food3","3","desc3"
"description","name","price"
"desc1","food1","1"
"desc2","food2","2"
"desc3","food3","3"
"price","name","description"
"1","food1","desc1"
"2","food2","desc2"
"3","food3","desc3"
Quote fields
Specify which field types should be quoted in the CSV output.
Options
All fields
(default)Non integer fields
No fields
- XML Input
- CSV Output - All fields
- CSV Output - Non integer fields
- CSV Output - No fields
<?xml version="1.0" encoding="UTF-8"?>
<breakfast_menu>
<food>
<name>food1</name>
<price>1</price>
<description>desc1</description>
</food>
<food>
<name>food2</name>
<price>2</price>
<description>desc2</description>
</food>
<food>
<name>food3</name>
<price>3</price>
<description>desc3</description>
</food>
</breakfast_menu>
"name","price","description"
"food1","1","desc1"
"food2","2","desc2"
"food3","3","desc3"
"name","price","description"
"food1",1,"desc1"
"food2",2,"desc2"
"food3",3,"desc3"
name,price,description
food1,1,desc1
food2,2,desc2
food3,3,desc3
XPath expression
Specify an XPath expression to indicate which element
is used for the conversion, read more about Using XML to CSV.
- XML Input
- CSV Output - //food
- CSV Output - //drink
<?xml version="1.0" encoding="UTF-8"?>
<breakfast_menu>
<food>
<name>food1</name>
<price>1</price>
<description>desc1</description>
</food>
<food>
<name>food2</name>
<price>2</price>
<description>desc2</description>
</food>
<food>
<name>food3</name>
<price>3</price>
<description>desc3</description>
</food>
<drink>
<name>drink1</name>
<price>1</price>
</drink>
<drink>
<name>drink2</name>
<price>2</price>
</drink>
</breakfast_menu>
"name","price","description"
"food1","1","desc1"
"food2","2","desc2"
"food3","3","desc3"
"name","price"
"drink1","1"
"drink2","2"
Using XML to CSV
The XML should follow this structure:
<root>
<element>
<subElement>
<subSubElement></subSubElement>
</subElement>
</element>
</root>
Processing is supported up to the subSubElement
level.
<?xml version="1.0" encoding="UTF-8"?> <!-- structure tags: -->
<items> <!-- root -->
<item> <!-- element -->
<firstName>Joe</firstName> <!-- subElement -->
<lastName>Foo</lastName> <!-- subElement -->
<age>21</age> <!-- subElement -->
<description> <!-- subElement -->
<title>Title</title> <!-- subSubElement -->
<body>Body</body> <!-- subSubElement -->
</description> <!-- subElement -->
</item> <!-- element -->
<item> <!-- element -->
<firstName>John</firstName> <!-- subElement -->
<lastName>Doe</lastName> <!-- subElement -->
<age>30</age> <!-- subElement -->
<description> <!-- subElement -->
<title>Title</title> <!-- subSubElement -->
<body>Body</body> <!-- subSubElement -->
</description> <!-- subElement -->
</item> <!-- element -->
</items> <!-- root -->
- Only one type of
element
will be processed, the first one that is encountered. - Header names are based on the unique
subElements
andsubSubElements
.SubSubElement
names include their parent element, formatted assubElement_subSubElement
.
- Multiple
subElements
orsubSubElements
with the same name inside the same parent are ignored.
Use the XSLT component or manually modify the XML to conform to the desired structure if:
- Attributes need to be processed.
- Multiple types of
elements
need to be processed. - Non-unique
subElements
orsubSubElements
within the sameelement
need to be processed.