Problem with tFileInputXML with empty tag

Highlighted
One Star

Problem with tFileInputXML with empty tag

Hi,
I have problem with tFileInputXML and empty with data like date or number. I use Java project and TOS Version: V2.1.1 Build id: r4583-20070715-2305.
I have this input file :
<?xml version="1.0" encoding="ISO-8859-15"?>
<DATA>
<SEQ>
<SEQ_NOM>CSTD_RLIS</SEQ_NOM>
<SEQ_VALEUR>0</SEQ_VALEUR>
<SEQ_DATEM>2005-05-01 12:00:00.000</SEQ_DATEM>
<SEQ_MIN>0</SEQ_MIN>
<SEQ_MAX>999999999</SEQ_MAX>
<SEQ_CYCLIQUE></SEQ_CYCLIQUE>
<SEQ_DEBUT></SEQ_DEBUT>
<SEQ_INC>1</SEQ_INC>
</SEQ>
<SEQ>
<SEQ_NOM>CSTD_RSEL</SEQ_NOM>
<SEQ_VALEUR>0</SEQ_VALEUR>
<SEQ_DATEM></SEQ_DATEM>
<SEQ_MIN>0</SEQ_MIN>
<SEQ_MAX>999999999</SEQ_MAX>
<SEQ_CYCLIQUE>0</SEQ_CYCLIQUE>
<SEQ_DEBUT>1</SEQ_DEBUT>
<SEQ_INC></SEQ_INC>
</SEQ>
</DATA>
Tag SEQ_DATEM is timestamp data.
Tags SEQ_CYCLIQUE, SEQ_DEBUT, SEQ_INC are Long or Integer data
When y try to load the file i have this error :
Exception in component tFileInputXML_1
java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:468)
at java.lang.Integer.parseInt(Integer.java:497)
at routines.system.ParserUtils.parseTo_Integer(ParserUtils.java:62)
at test.test.Test.tFileInputXML_1Process(Test.java:189)
at test.test.Test.main(Test.java:422)
Empty tag are consider like empty string not null value Smiley Sad . How can i resolve my problem ?
I join the image of my schema.

Regards,
One Star

Re: Problem with tFileInputXML with empty tag

Hi,
The problem could be that the contents of the tags are read as string, if you specify that a certain column is an Integer, TOS will create a class Integer parsing the string.
Of course you can't obtain an Integer class from an empty string.
I think that you can set all the columns as string and after you can work with Integers and Longs using a tMap.
Regards
One Star

Re: Problem with tFileInputXML with empty tag

Hello,
we have just the same problem that you with tFileInputXML component.
We have been looking for a better solution and we have discovered that problem is on code generated.
When tFileInputXML component is looking for the data of a XML node is using XPath (org.dom4j.xpath.DefaultXPath class of dom4j-1.6.1.jar exactly), and when node is not present or value is empty, the "valueOf" method is returning "" (empty String), instead of null value.
This is the default implementation of DOM4J API, so we think that this API is working fine, according to standar.
(If this isn't correct then maybe this API must fix this bug.)
With Talend, in the java source code generated of tFileInputXML component, there is a line to prevent it (null value) but the comparation is only against null value, not empty value.
The line is like: if (str_tFileInputXML_1 != null)
Then the solution is about to do both comparations, prevent it about null value and about empty value, like this:
if (str_tFileInputXML_1 != null && str_tFileInputXML_1.length() > 0)

Therefore, we think that a possible solution is modify the tFileInputXML component:
In tFileInputXML_begin.javajet, line 111, where it's write "if (str_<%=cid %> != null ) { "
replace it with "if (str_<%=cid %> != null && str_<%=cid %>.length() > 0) { "
With this change, the mapping from XML data to Talend/Java types is possible and very easy.
We have made this change and all is working fine, so we think that it's a solution for this presumptive "bug".

NOTE: I suppose that in perl lenguage is possible to do the same, but we can't try it.

Thanks
One Star

Re: Problem with tFileInputXML with empty tag

Hello again,
we are using the latest stable version:
Talend Version: 2.2.2
Build id: r7074-20071116-2048
Thanks
Community Manager

Re: Problem with tFileInputXML with empty tag

Hi dmerino
We will consider your suggestion and learn your code.
Thanks for your support!
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Problem with tFileInputXML with empty tag

I think that the best solution is to open a bugtracker for this bug. We have the same problem and it is a big issue in TALEND right now.
There is another case related to this one : Problem when XML tag element is not present in the XML file.
Indeed in XML if a field is not mandatory it can be present or not in the file.
In this case TALEND fill the field with empty string. It is not good the field must be initialised to NULL or better excluded from the schema.
One Star

Re: Problem with tFileInputXML with empty tag

Hi,
I tried the solution of dmerino but it doesn't work.
Indeed, in the generated java code, no value is assigned to the field if it's null or empty.
So the value is not changed and it?s the previous value (of the previous element)
By exemple, with the file :
<client>
<name>name1</name>
<firstname>firstname1</firstame>
</client>
<client>
<name>name2</name>
</client>
<client>
<name></name>
<firstname>firstname3</firstame>
</client>
The log row result with dmerino solution is :
name1|firstname1
name2|firstname1
name2|firstname3
The lgood og row result is :
name1|firstname1
name2|
|firstname3
For information, we use the java version v2.2.2 r7074.
I did another modification in tFileInputXML to fix the problem.
I opened a bugtracker (where you can see the modified code) :
http://www.talendforge.org/bugs/view.php?id=2834
Employee

Re: Problem with tFileInputXML with empty tag

Hello,
I have added a note in this 2834.
Regards,