1
Mapping data from Excel to XML - how to handle optional fields
Question asked by Gianluca Rattacaso - 2/16/2023 at 2:32 PM
Answered
Hi there, 

I'm new with Liquid Studio. 

I'm trying to map rows from an Excel file into an XML with multiple occurrences.
The issue I'm running into is the following, when a field is optional in the xsd and the matching field in the Excel is empty. Instead of just skipping the element in the XML, the mapper throws an error. (The error occurs when the mapper tries to convert an empty 'date' field into DateTime).

Example ;

Excel

field A (required)field B (required)field C(optional)Field D (required)
row 1value_1value_2value_3value_4
row 2value_5value_6
value_7

I'm hoping to get an XML as follows ;

XML 
<element_1>
   <field_A>value_1</field_A>
   <field_B>value_2</field_B>
   <field_C>value_3</field_C>
   <field_D>value_4</field_D>
</element_1>
<element_2>
   <field_A>value_1</field_A>
   <field_B>value_2</field_B>
   <field_D>value_4</field_D>
</element_2>

Sorry for the rather simple question but I wonder if such a behavior is feasible. 

Thank you,
Gianluca

2 Replies

Reply to Thread
0
Liquid Support Replied
Employee Post
The following transform should do what you want, 
However if you have the following source data
 
Col1Col2Col3
05/09/1999value 145345
01/06/2003
345

Value 2345

and you set Col1 up as a Date, then when it reads the empty value it tries to cast it to a Date - which fails.

Having reviewed this functionality we think it should return a 'null' value when no data is present in a cell, which would see the above transform generating the data 

<Root>
    <Row>
        <MyDate>1999-09-05</MyDate>
        <MyString>value 1</MyString>
        <MyInt>45345</MyInt>
    </Row>
    <Row>
        <MyDate>2003-06-01</MyDate>
        <MyString></MyString>
        <MyInt>345</MyInt>
    </Row>
    <Row>
        <MyString>Value 2</MyString>
        <MyInt>345</MyInt>
    </Row>
</Root>
We will make the changes in the next point release.


In the meantime you can do this to work around the issue

Where Col1 is defined as containing a "string".

0
Liquid Support Replied
Employee Post Marked As Answer
Hi,

A fix for this issue is now available in v20.2.5:

Empty fields now create empty sequences unless the data type is a string, in which case an empty string is returned.

Reply to Thread