[resolved] Remove empty tags from xml

One Star

[resolved] Remove empty tags from xml

TIS 3.1.3.
I have an input csv file with empty fields that I want to convert to xml. How do I get tFileOutputXML not to output empty tags or in a more advanced case tFileOutputMSXML ( I unchecked Create empty element if needed but it made no difference). The generated Java code appears to only check for null values not empty values.

Accepted Solutions
One Star

Re: [resolved] Remove empty tags from xml

If it works in TOS3.2.0.M3, I think it's probably a bug in 3.1.3 which has been resolved. I'm now able to reproduce the issue in TOS 3.1.3. The problem seems to appear when there are null values in other sections than the loop one.
When I first try it today, I had null values only in the loop section, that's why everything worked fine.
Does anyone have any info about this?
Regards,
Karine
One Star

Re: [resolved] Remove empty tags from xml

Yes it was a bug in tis3.1.3 - bug ref 0009032.

All Replies
One Star

Re: [resolved] Remove empty tags from xml

What you mean by null and emply?
Are those different?
null is understood by java language but empty does not have any meaning in java. Might be for humans, empty has some meaning.

The generated Java code appears to only check for null values not empty values.

What you mean by empty here.

Thanks and Regards,
pravu Mishra.
One Star

Re: [resolved] Remove empty tags from xml

Values that have no content i.e. empty. So in the delimited file a field has no content but in not treated by Java as null.
So the Java code needs to test
String s = ...
if (s == null || s.equals(""))...
One Star

Re: [resolved] Remove empty tags from xml

I guess there might be some blank characters in those fields.
Could you please try by trimming the field(String type).
Thanks and Regards,
Pravu Mishra.
One Star

Re: [resolved] Remove empty tags from xml

They wouldn't be empty if they had blank characters.
One Star

Re: [resolved] Remove empty tags from xml

So you consider blank as a character. Smiley Happy
Thanks and Regards,
One Star

Re: [resolved] Remove empty tags from xml

if you regard blank as space then yes. These fields do not contain anything. In a hex editor all that is present are the delimiters.
One Star

Re: [resolved] Remove empty tags from xml

Hi janhess,
Have you tried to replace "" with null? You can use a tReplace between the tFileInputDelimited and the tFileOutputMSXML, and uncheck the "create emty element if needed" option.
Regards,
Karine
One Star

Re: [resolved] Remove empty tags from xml

I tried doing that using a tMap in the middle but the resultant xml had the wrong structure - the loop wasn't generated. I'll try tReplace.
Thanks
One Star

Re: [resolved] Remove empty tags from xml

Hi Karine,
I tried that but got the same result as using tMap - I loose the loop element so I get one set of xml for every loop element.
Thanks
Jan
One Star

Re: [resolved] Remove empty tags from xml

Maybe your XML tree isn't well configured. Can you post a screenshot of your xml tree and an example of the expected xml file?
One Star

Re: [resolved] Remove empty tags from xml

I've tried different options as below but I either get empty tags or without empty tags I don't get the z304 section repeated.
Structure should be like this but without the empty tags.
<p_file_20>
<patron_record>
<z303>
<match_id_type>02</match_id_type>
<match_id>999907735</match_id>
<record_action>A</record_action>
<z303_id>999907735</z303_id>
<z303_user_type></z303_user_type>
<z303_con_lng>ENG</z303_con_lng>
<z303_name>xxxxxxx, FRED</z303_name>
<z303_title>MR</z303_title>
<z303_delinq_1></z303_delinq_1>
<z303_delinq_n_1></z303_delinq_n_1>
<z303_budget></z303_budget>
<z303_profile_id>03 PGRAD</z303_profile_id>
<z303_ill_library></z303_ill_library>
<z303_home_library></z303_home_library>
<z303_note_1></z303_note_1>
<z303_ill_total_limit></z303_ill_total_limit>
<z303_ill_active_limit></z303_ill_active_limit>
<z303_birth_date>19840930</z303_birth_date>
<z303_export_consent></z303_export_consent>
<z303_proxy_id_type></z303_proxy_id_type>
<z303_send_all_letters>Y</z303_send_all_letters>
<z303_plain_html>P</z303_plain_html>
<z303_want_sms></z303_want_sms>
<z303_title_req_limit></z303_title_req_limit>
<z303_gender>M</z303_gender>
</z303>
<z305>
<record_action>X</record_action>
<z305_id>999907735</z305_id>
<z305_sub_library>xxxxxxx</z305_sub_library>
<z305_bor_type>PT</z305_bor_type>
<z305_bor_status>03</z305_bor_status>
<z305_registration_date></z305_registration_date>
<z305_expiry_date>20140930</z305_expiry_date>
</z305>
<z308>
<record_action>X</record_action>
<z308_key_type>02</z308_key_type>
<z308_key_data>999907735</z308_key_data>
<z308_verification></z308_verification>
<z308_verification_type>00</z308_verification_type>
<z308_status>AC</z308_status>
<z308_encryption>H</z308_encryption>
</z308>
<z304>
<record_action>A</record_action>
<z304_id>999907735</z304_id>
<z304_sequence>01</z304_sequence>
<z304_address_0>MR FRED xxxxxxx</z304_address_0>
<z304_address_1>121 FRONT STREET</z304_address_1>
<z304_address_2>xxxxxxx</z304_address_2>
<z304_address_3>xxxxxxx</z304_address_3>
<z304_address_4>%</z304_address_4>
<z304_zip></z304_zip>
<z304_email_address>F.xxxxxxx@aaa.com</z304_email_address>
<z304_telephone>01111586270</z304_telephone>
<z304_date_from></z304_date_from>
<z304_date_to></z304_date_to>
<z304_address_type>01</z304_address_type>
<z304_telephone_2></z304_telephone_2>
</z304>
<z304>
<record_action>A</record_action>
<z304_id>999907735</z304_id>
<z304_sequence>02</z304_sequence>
<z304_address_0>MR FRED xxxxxxx</z304_address_0>
<z304_address_1>10 MONKS DRIVE</z304_address_1>
<z304_address_2>xxxxxxx</z304_address_2>
<z304_address_3>xxxxxxx</z304_address_3>
<z304_address_4></z304_address_4>
<z304_zip>XX1 1XX</z304_zip>
<z304_email_address>F.xxxxxxx@aaa.com</z304_email_address>
<z304_telephone>0999 9991199</z304_telephone>
<z304_date_from></z304_date_from>
<z304_date_to></z304_date_to>
<z304_address_type>03</z304_address_type>
<z304_telephone_2></z304_telephone_2>
</z304>
<z304>
<record_action>X</record_action>
<z304_id>999907735</z304_id>
<z304_sequence>03</z304_sequence>
<z304_address_0>%</z304_address_0>
<z304_address_1>%</z304_address_1>
<z304_address_2>%</z304_address_2>
<z304_address_3>%</z304_address_3>
<z304_address_4>%</z304_address_4>
<z304_zip></z304_zip>
<z304_email_address></z304_email_address>
<z304_telephone></z304_telephone>
<z304_date_from></z304_date_from>
<z304_date_to></z304_date_to>
<z304_address_type></z304_address_type>
<z304_telephone_2></z304_telephone_2>
</z304>
</patron_record>
</p_file_20>
One Star

Re: [resolved] Remove empty tags from xml

I tried to reproduce your issue with a similar structure but it works fine for me...
Is the generated file structure ok when you link directly the tFileInputDelimited to the tFileOutputMSXML or tAdvancedFileOutputXML?
Can you share an example of your input file? Are the values of the others sections (z303,z305,z308) the same for each row of this file?
One Star

Re: [resolved] Remove empty tags from xml

I've tried to attach some test data but it doesn't seem to let me.
The data below is tab delimited.
A 02 111111111 MR WICK, ALEX 19840930 03 PGRAD Y ENG P M 01 03 01 X 02 111111111 00 AC H X AAA50 PT 03 20140930 A 01 01 MR ALEX WICK 12 THE STREET PLACE CITY % 334455667788 A.wick@AAA.COM
A 02 111111111 MR WICK, ALEX 19840930 03 PGRAD Y ENG P M 01 03 01 X 02 111111111 00 AC H X AAA50 PT 03 20140930 A 02 03 MR ALEX WICK 10 THE DRIVE THERE TOWN AB4 4AF 2324536335 A.wick@AAA.COM
A 02 111111111 MR WICK, ALEX 19840930 03 PGRAD Y ENG P M 01 03 01 X 02 111111111 00 AC H X AAA50 PT 03 20140930 X 03 % % % % %
A 02 222222222 MISS FISHER, HELEN 19870723 02 UGRAD Y ENG P F 01 03 01 X 02 222222222 00 AC H A AAA50 UF 02 20120615 A 01 01 MISS HELEN FISHER 10 THE RD HERE CITY AE2 3AR 3245645758 a.fisher@aaa.com
A 02 222222222 MISS FISHER, HELEN 19870723 02 UGRAD Y ENG P F 01 03 01 X 02 222222222 00 AC H A AAA50 UF 02 20120615 A 02 02 MISS HELEN FISHER 14 ANOTHER RD TOWN COUNTY AG10 8AT 23535647567 a.fisher@aaa.com
A 02 222222222 MISS FISHER, HELEN 19870723 02 UGRAD Y ENG P F 01 03 01 X 02 222222222 00 AC H A AAA50 UF 02 20120615 X 03 % % % % %
A 02 333333333 MR MACK, ALEX 19870401 03 PGRAD Y ENG P M 01 03 01 X 02 333333333 00 AC H A AAA50 PF 03 20100930 X 01 01 MR ALEX MACK 26 THE AVENUE SOMEWHERE AE2 2AP a.mack@aaa.com
A 02 333333333 MR MACK, ALEX 19870401 03 PGRAD Y ENG P M 01 03 01 X 02 333333333 00 AC H A AAA50 PF 03 20100930 A 02 03 MR ALEX MACK A HOUSE A ROAD A TOWN A COUNTY 235356467467 a.mack@aaa.com
A 02 333333333 MR MACK, ALEX 19870401 03 PGRAD Y ENG P M 01 03 01 X 02 333333333 00 AC H A AAA50 PF 03 20100930 X 03 % % % % %
One Star

Re: [resolved] Remove empty tags from xml

Well I've managed to get it to work in TOS3.2.0.M3_r28760 using the tReplace to replace empty strings with null. Now all I have to do is get it to work at 3.1.3.
One Star

Re: [resolved] Remove empty tags from xml

If it works in TOS3.2.0.M3, I think it's probably a bug in 3.1.3 which has been resolved. I'm now able to reproduce the issue in TOS 3.1.3. The problem seems to appear when there are null values in other sections than the loop one.
When I first try it today, I had null values only in the loop section, that's why everything worked fine.
Does anyone have any info about this?
Regards,
Karine
One Star

Re: [resolved] Remove empty tags from xml

Yes it was a bug in tis3.1.3 - bug ref 0009032.
One Star

Re: [resolved] Remove empty tags from xml

Another option would be in the tMap, use an expression that checks the length of the string, if its 0 then send null as the output, do something like this:
StringHandling.LEN(theValue) == 0 ? null : theValue