RequirementsThis utility converts a flat file containing one or more logical documents to one or more XML instance documents, each representing a single logical document. Here's a summary of the required functionality.
Running the UtilityThis section provides instructions for running the flat file to XML conversion utility from the command line. For Java:
or
For C++ on Win32:
or
Options follow the parameters except for the help option, which may be specified by itself. Parameters:
Options:
Restrictions: Unless otherwise noted, all numeric limits may be modified by changing parameters in the program source and appropriate type definitions in the file description document schemas.
Sample Input and Output: InvoiceAs in Chapter 7, we're going to use invoices from Big Daddy's Gourmet Cocoa for our example. However, Big Daddy has now upgraded to a more capable order management and bookkeeping system. The new system supports a more comprehensive flat, hierarchical file structure than the CSV formats supported by the previous system. The simple invoice example is composed of two levels of record groups. The group at the top level is the invoice itself, consisting of a header record, ship to address, one or more line item groups, and a summary record. The second group, the line item group, contains a line item record and an item description record. This particular file has variable length records. Although Big Daddy's system uses variable length records, we could just as easily specify a fixed length record. Table 8.1 shows the logical layout of the invoice file. Figure 8.1 shows the sample input invoice flat file. Table 8.1. Logical Layout for the Invoice
Figure 8.1 Sample Input Flat File (Invoices.dat) [View full width] 10 20 30 40 50 60 70 80 90 100 110 120 130 HDRBQ003 2002041 20021112AZ999345 20021212 SHPYazoo Grocers - NE Distribution Center 12 Industrial Parkway NW Portland ME 04101 LINHCVAN 120000000259000003108 DSCInstant Hot Cocoa Mix - Vanilla flavor LINHCMIN 240000000253000006072 DSCInstant Hot Cocoa Mix - Mint flavor SUM0000009180 2 HDRBQ003 2002042 20021112AW999346 20021212 SHPYazoo Grocers - SE Distribution Center Dock 37 3975 Hwy 75 Atoka OK 74525 LINHCVAN 360000000259000009324 DSCInstant Hot Cocoa Mix - Vanilla flavor LINHCMIN 720000000253000018216 DSCInstant Hot Cocoa Mix - Mint flavor SUM0000027540 2 HDRAY001 2002043 200211122002-0967 20021212 SHPCorner Drug and Sundries 14 Main Street Wichita KS 67201 LINHCVAN 240000000259000006216 DSCInstant Hot Cocoa Mix - Vanilla flavor SUM0000006216 1 HDRBR095 2002044 200211124397-0498 20021212 SHPBig Box Discounters - Store # 97 37 MegaMall Azusa CA 91702 LINHCMIN 1200000000253000030360 DSCInstant Hot Cocoa Mix - Mint flavor LINHCVAN 3600000000259000093240 DSCInstant Hot Cocoa Mix - Vanilla flavor LINHCDUC 2400000000259000062160 DSCInstant Hot Cocoa Mix - Dutch Chocolate flavor SUM0000185760 3 HDRBR095 2002045 200211124345-0498 20021212 SHPBig Box Discounters - Store # 45 45 Highway 76 Branson MO 65615 LINHCMIN 720000000253000018216 DSCInstant Hot Cocoa Mix - Mint flavor LINHCDUC 960000000259000024864 DSCInstant Hot Cocoa Mix - Dutch Chocolate flavor SUM0000043080 2 HDRDQ349 2002046 20021112987-43671 20021212 SHPMaple Leaf Grocers - DC #1 987 Yorkland Blvd Willowdale ON M2J 4Y8 CAN LINHCMOC 36000000000269000096840 DSCInstant Hot Cocoa Mix - Mocha flavor SUM0000096840 1 Listed below are the first three XML documents produced by the utility from this input file. FlatInvoice001.xml<?xml version="1.0" encoding="UTF-8"?> <FlatInvoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FlatInvoice.xsd"> <Header> <RecordID>HDR</RecordID> <CustomerNumber>BQ003</CustomerNumber> <InvoiceNumber>2002041</InvoiceNumber> <InvoiceDate>2002-11-12</InvoiceDate> <PONumber>AZ999345</PONumber> <DueDate>2002-12-12</DueDate> </Header> <ShipTo> <RecordID>SHP</RecordID> <ShipToName> Yazoo Grocers - NE Distribution Center </ShipToName> <ShipToStreet1>12 Industrial Parkway NW</ShipToStreet1> <ShipToCity>Portland</ShipToCity> <ShipToStateOrProvince>ME</ShipToStateOrProvince> <ShipToPostalCode>04101</ShipToPostalCode> </ShipTo> <LineItemGroup> <LineItem> <RecordID>LIN</RecordID> <ItemID>HCVAN</ItemID> <ItemQuantity>12</ItemQuantity> <UnitPrice>2.59</UnitPrice> <ExtendedPrice>31.08</ExtendedPrice> </LineItem> <ItemDescription> <RecordID>DSC</RecordID> <Description> Instant Hot Cocoa Mix - Vanilla flavor </Description> </ItemDescription> </LineItemGroup> <LineItemGroup> <LineItem> <RecordID>LIN</RecordID> <ItemID>HCMIN</ItemID> <ItemQuantity>24</ItemQuantity> <UnitPrice>2.53</UnitPrice> <ExtendedPrice>60.72</ExtendedPrice> </LineItem> <ItemDescription> <RecordID>DSC</RecordID> <Description> Instant Hot Cocoa Mix - Mint flavor </Description> </ItemDescription> </LineItemGroup> <Summary> <RecordID>SUM</RecordID> <TotalAmount>91.80</TotalAmount> <NumberOfLines>2</NumberOfLines> </Summary> </FlatInvoice> FlatInvoice002.xml<?xml version="1.0" encoding="UTF-8"?> <FlatInvoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FlatInvoice.xsd"> <Header> <RecordID>HDR</RecordID> <CustomerNumber>BQ003</CustomerNumber> <InvoiceNumber>2002042</InvoiceNumber> <InvoiceDate>2002-11-12</InvoiceDate> <PONumber>AW999346</PONumber> <DueDate>2002-12-12</DueDate> </Header> <ShipTo> <RecordID>SHP</RecordID> <ShipToName> Yazoo Grocers - SE Distribution Center </ShipToName> <ShipToStreet1>Dock 37</ShipToStreet1> <ShipToStreet2>3975 Hwy 75</ShipToStreet2> <ShipToCity>Atoka</ShipToCity> <ShipToStateOrProvince>OK</ShipToStateOrProvince> <ShipToPostalCode>74525</ShipToPostalCode> </ShipTo> <LineItemGroup> <LineItem> <RecordID>LIN</RecordID> <ItemID>HCVAN</ItemID> <ItemQuantity>36</ItemQuantity> <UnitPrice>2.59</UnitPrice> <ExtendedPrice>93.24</ExtendedPrice> </LineItem> <ItemDescription> <RecordID>DSC</RecordID> <Description> Instant Hot Cocoa Mix - Vanilla flavor </Description> </ItemDescription> </LineItemGroup> <LineItemGroup> <LineItem> <RecordID>LIN</RecordID> <ItemID>HCMIN</ItemID> <ItemQuantity>72</ItemQuantity> <UnitPrice>2.53</UnitPrice> <ExtendedPrice>182.16</ExtendedPrice> </LineItem> <ItemDescription> <RecordID>DSC</RecordID> <Description> Instant Hot Cocoa Mix - Mint flavor </Description> </ItemDescription> </LineItemGroup> <Summary> <RecordID>SUM</RecordID> <TotalAmount>275.40</TotalAmount> <NumberOfLines>2</NumberOfLines> </Summary> </FlatInvoice> FlatInvoice003.xml<?xml version="1.0" encoding="UTF-8"?> <FlatInvoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FlatInvoice.xsd"> <Header> <RecordID>HDR</RecordID> <CustomerNumber>AY001</CustomerNumber> <InvoiceNumber>2002043</InvoiceNumber> <InvoiceDate>2002-11-12</InvoiceDate> <PONumber>2002-0967</PONumber> <DueDate>2002-12-12</DueDate> </Header> <ShipTo> <RecordID>SHP</RecordID> <ShipToName>Corner Drug and Sundries</ShipToName> <ShipToStreet1>14 Main Street</ShipToStreet1> <ShipToCity>Wichita</ShipToCity> <ShipToStateOrProvince>KS</ShipToStateOrProvince> <ShipToPostalCode>67201</ShipToPostalCode> </ShipTo> <LineItemGroup> <LineItem> <RecordID>LIN</RecordID> <ItemID>HCVAN</ItemID> <ItemQuantity>24</ItemQuantity> <UnitPrice>2.59</UnitPrice> <ExtendedPrice>62.16</ExtendedPrice> </LineItem> <ItemDescription> <RecordID>DSC</RecordID> <Description> Instant Hot Cocoa Mix - Vanilla flavor </Description> </ItemDescription> </LineItemGroup> <Summary> <RecordID>SUM</RecordID> <TotalAmount>62.16</TotalAmount> <NumberOfLines>1</NumberOfLines> </Summary> </FlatInvoice> |