Menu

segmented-line/CSV Problem

Help
2003-12-21
2003-12-24
  • Mitch Christensen

    Hey,

    I notice that when using CSV data with segmented lines, I can only use <segment-value/>'s in the first column/field.  In other words, I can only identify different line formats based on data in the first column/field of each line.

    For example, if my data looks like this,

    fmt1,marker1,one,two,three
    fmt2,marker2,three,four,five

    I can switch based on 'fmtX' fine, but not 'markerX'.

    This is demonstrated with the following FlatToXml config file using the above data.  As it stands now, this config file doesn't work.  However, changing first segment definition to the following,

          <segment-column>1</segment-column>
          <segment-width>4</segment-width>
          <segment-value>fmt1</segment-value>

    makes everthing work fine.

    I *really* need to be able to select rows based on subsequent columns.

    Any suggestions?

    TIA,
    -Mitch

    <?xml version="1.0" encoding="UTF-8"?>

    <conversion>
      <header>
        <output-document>
          <root-element>order</root-element>
          <row-element>not-applicable-here</row-element>
        </output-document>
        <input-document>
          <conversion-type>segmented-line</conversion-type>
          <line-ending>CR</line-ending>
          <field-separator>,</field-separator>
        </input-document>
      </header>
      <line-segments>
        <segment>
          <segment-name>header</segment-name>
          <segment-column>5</segment-column>
          <segment-width>7</segment-width>
          <segment-value>marker1</segment-value>
          <begin-group-name>Format1</begin-group-name>
          <csv-fields>
            <field>
              <field-name>test1</field-name>
              <field-number>3</field-number>
            </field>
            <field>
              <field-name>test2</field-name>
              <field-number>4</field-number>
            </field>
            <field>
              <field-name>test3</field-name>
              <field-number>5</field-number>
            </field>
          </csv-fields>
        </segment>
        <segment>
          <segment-name>header</segment-name>
          <segment-column>1</segment-column>
          <segment-width>4</segment-width>
          <segment-value>fmt1</segment-value>
          <begin-group-name>Format2</begin-group-name>
          <csv-fields>
            <field>
              <field-name>test1</field-name>
              <field-number>3</field-number>
            </field>
            <field>
              <field-name>test2</field-name>
              <field-number>4</field-number>
            </field>
            <field>
              <field-name>test3</field-name>
              <field-number>5</field-number>
            </field>
          </csv-fields>
        </segment>
      </line-segments>
    </conversion>

     
    • Mitch Christensen

      This turned out to be a bug in FlatFileConverter.handleSegmentedLine().  The line.substring(column, width) in the 'if' statement is incorrect, and should read line.substring(column, column + width).  This is becase String.substring() takes a beginning and ending *index*, not a beginning index and length (see the JDK 1.4 JavaDoc).  Making this change now properly recognizes patterns beyond the first character.

       
    • Mitch Christensen

      I've opened ticket #865397 for this issue.

       
    • bruce mcdonald

      bruce mcdonald - 2003-12-24

      Thanks

      I will be fixing this now.  Initially will be rolling fix into the HEAD branch in CVS

      Bruce.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.