How to ignore blank line(s)

1,729 views
Skip to first unread message

ctm...@gmail.com

unread,
Jun 19, 2013, 2:56:19 PM6/19/13
to bea...@googlegroups.com
HI kevin,

I have xml file format like:
        <stream name="employee.csv" format="csv">
<typeHandler name="hotListTypeIdHandler" class="com.employeeTypeIdHandler" />
  <record name="employee" class="map">
  <field name="name" position="0" minOccurs="1" trim="true"/>
  <field name="id" position = "3" minOccurs="0" trim="true" typeHandler="employeeTypeIdHandler"/>
  <field name="salary" position = "5" minOccurs="0" trim="true" minOccurs="1" />
  </record> 
</stream>


and csv file looks like:
Michael J, 13423,45000

Steven M, 34322, 50000
Ulban K, 31222, 45000


Bind J, 321212, 40000


Because there are many blank lines in the file (middle and bottom), how can I skip these lines?

Kevin

unread,
Jun 19, 2013, 10:54:21 PM6/19/13
to bea...@googlegroups.com
Hello,

If there are no spaces on the blank lines, something like this would work:

  <stream name="stream" format="csv">

    <record name="record" class="map">

      <field name="field" rid="true" regex=".+" />

    </record>

    <record name="ignored" ridLength="1">

      <field name="field" rid="true" regex="^$" />

    </record>

  </stream>


We also assume in 'record' that the first field will have at least one character.

Thanks,
Kevin

ctm...@gmail.com

unread,
Jun 20, 2013, 9:24:59 AM6/20/13
to bea...@googlegroups.com
Thanks Kevin. It works.

ota...@otavio.com.br

unread,
Jun 26, 2013, 9:30:17 PM6/26/13
to bea...@googlegroups.com
How I can do this to fixedlength? I have a blank line (zero length) at end of file.

I got this error: Invalid field 'field', in record 'ignored', in stream 'debits': length required for fixed length fields

When add attribute length, I got this error:  ==> Invalid 'notUsed':  Expected minimum 1 occurrences

Thank you

ota...@otavio.com.br

unread,
Jun 27, 2013, 1:00:22 AM6/27/13
to bea...@googlegroups.com
Reading the docs, I see the ignoreUnidentifiedRecords attribute at stream level, that ignore unmapped lines.

Thanks

Kevin

unread,
Jun 27, 2013, 10:25:57 PM6/27/13
to bea...@googlegroups.com
That would work, or you could experiment with ridLength.  I didn't try it myself, but something like:

  <stream name="stream" format="fixedlength">

    <record name="record" class="map" ridLength="1+">

      <!-- fields -->

    </record>

    <record name="ignored" ridLength="0" />

  </stream>


Thanks,
Kevin

syeda samreen

unread,
Aug 17, 2016, 2:30:49 AM8/17/16
to beanio-users

Hay i tried with above two methods, but it doesn't seem to work . Could you please help with this.

My delimited tab file format is 

Direct Initial 15/05/16 Leeds 26-G-14-046309-002-00007
Direct Initial 15/05/16 Leeds 26-G-14-046309-002-00007

Direct Initial 15/05/16 Leeds 26-G-14-046309-002-00007
Direct Initial 15/05/16 Leeds 26-G-14-046309-002-00007

i would like to skip the empty lines that occur any where with in the file

My mapping:
 <stream name="arcadiaPOMapping" format="delimited" strict="true">
    <parser>
        <property name="escape" value="\n" />
<property name="delimiter" value="\t" />
</parser>
<record name="blankLine" minOccurs="1" maxOccurs="1"/>
<record name="POMapping" class="com.nla.TabFileSchema.AcdTabDelimitedFFVO" ridLength="1+">
<field name="shipmentType" />
<field name="recordType" />
<field name="expectedShipmentDate" type="date" format="dd/MM/yy" />
<field name="deliverTo" />
     </record>
    </stream>

tried with escape sequence as well.. but unlucky :(

Could any one help me with skipping empty lines?

Vitalii Tymchyshyn

unread,
Aug 17, 2016, 10:51:42 AM8/17/16
to beanio-users

Try making rid one of the fields, using length or pattern. It worked for me.

Best regards, Vitalii Tymchyshyn


Ср, 17 серп. 2016 02:30 користувач syeda samreen <sam.sa...@gmail.com> пише:
--
You received this message because you are subscribed to the Google Groups "beanio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beanio+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Luiz Nazari

unread,
Apr 6, 2020, 6:17:22 PM4/6/20
to beanio-users
Neither the solutions pointed on this discussion worked for me.
I'm using a "delimiter" stream and the files I must read contains blank rows (only with whitespace characters), thus, whenever I set a field at position 0 (first column of the csv), BeanIO reads it as the first column and then fails when validating the next columns  (inexistent for this blank row).

I tried to mark all columns as not required (minOccurs = 0), BeanI read successfully, but I end up with an empty object.

So I worked out a solution by setting the first column as "rid = true" and regex "^.*\\S+.*$" (matching a content with at least one non-whitespace character) and set the stream to "ignoreUnidentifiedRecords = true".
Reply all
Reply to author
Forward
0 new messages