On this Page

    _parser.fixedToXml

    Fixed-column data file to XML.

    Syntax

    _parser.fixedToXml(fromfile, tofile, format)

    Parameters

    fromfile is the existing file containing fixed-column data records.

    tofile is the name of a new file that will get created with the XML equivalent of the fromfile.

    format is a JavaScript object that describes the structure of the data record. This will typically be a JavaScript constant description such as:

    {first: {from:10, width:30, trim:'right'},
     second: {from:50, width:5, trim:'both'},
     ...}

    As can be seen from the above example each data field (first, second, etc) has an associated definition of how to extract the requisite data. from defines the data column where the data field begins (first column is number 0). width is the field's column width. trim is an optional setting that indicates whether leading or trailing blanks should be removed automatically:

    left removes leading blanks.

    right removes trailing blanks.

    both removes leading and trailing blanks.

    none does not remove any blanks. This is the default setting.

    Returned Value

    A return value of zero indicates a successful conversion. Other possible error return codes:

    -904 - could not open the fromfile.

    -905 - could not open the tofile.

    -906 - a conversion error occurred converting one of the data records.

    -907 - the format definition contains invalid or incorrect information. A field could not be extracted.

    Description

    This routine will convert an entire file of fixed-format records into an equivalent XML file.

    Example

    Consider a file C:/DocOrigin/test/Fixed.txt that contains fix-format records. Here's a sample of some of those records:

               1         2         3         4         5         6         7         8         9         
    0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012
               1      AK036    Happy Cat Activity Centre BlEach          23.12   0.00       23.12
               0      SC180    S/P Swing N Play Cat Toy*DELEach           1.10   7.00        0.00
               3      AH589    Atlas 10 Pet Carry Entry LvlEach          22.00   7.00       20.46
               4      AH590    Atlas 20 Pet Carry Entry LvlEach          27.50   7.00       25.58
               2      VP611    VP Super All Wormer Cat 4 TaEach           9.25   7.00        8.60
               ...

    The following code will convert that file to an equivalent XML file.

    var from = "C:/DocOrigin/test/Fixed.txt";
    var to = "C:/DocOrigin/test/Fixed.xml";
    
    var sFormat = { Quantity:{from:6, width:6, trim:'both'},
     			Code:{from:16, width:7, trim:'both'},
     			Description:{from:27, width:28, trim:'both'},
     			Price:{from:64, width:10, trim:'both'},
     			Discount:{from:74, width:10, trim:'both'},
     			Charged:{from:84, width:10, trim:'both'},
     			Net:{from:94, width:12, trim:'both'}  };
    
    _parser.fixedToXml(from, to, sFormat);

    This will produce a new file C:/DocOrigin/test/Fixed.xml that looks like:

    <?xml version="1.0" encoding="UTF-8"?>
    <XMLData>
      <Document>
        <Quantity>1</Quantity>
        <Code>AK036</Code>
        <Description>Happy Cat Activity Centre Bl</Description>
        <Price>23.12</Price>
        <Discount>0.00</Discount>
        <Charged>23.12</Charged>
        <Net>23.12</Net>
      </Document>
      <Document>
        <Quantity>0</Quantity>
        <Code>SC180</Code>
        <Description>S/P Swing N Play Cat Toy*DEL</Description>
        <Price>1.10</Price>
        <Discount>7.00</Discount>
        <Charged>0.00</Charged>
        <Net>0.00</Net>
      </Document>
      <Document>
        <Quantity>3</Quantity>
        <Code>AH589</Code>
        <Description>Atlas 10 Pet Carry Entry Lvl</Description>
        <Price>22.00</Price>
        <Discount>7.00</Discount>
        <Charged>20.46</Charged>
        <Net>61.38</Net>
      </Document>
      <Document>
        <Quantity>4</Quantity>
        <Code>AH590</Code>
        <Description>Atlas 20 Pet Carry Entry Lvl</Description>
        <Price>27.50</Price>
        <Discount>7.00</Discount>
        <Charged>25.58</Charged>
        <Net>102.30</Net>
      </Document>
      <Document>
        <Quantity>2</Quantity>
        <Code>VP611</Code>
        <Description>VP Super All Wormer Cat 4 Ta</Description>
        <Price>9.25</Price>
        <Discount>7.00</Discount>
        <Charged>8.60</Charged>
        <Net>17.20</Net>
      </Document>
      ...
    </XMLData>

    See Also

    _parser.delimited
    _parser.delimitedToXml
    _parser.fixed
    _parser.parms