XML to Flat File: Functionality and OperationRequirementsThe general requirement for this utility is to convert one or more XML instance documents, each representing a single logical document, into a single flat file. Here's a summary of the required functionality.
Running the UtilityThis section provides instructions for running the XML to flat file 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: The restrictions are the same as those specified for the flat file to XML utility, plus the following.
Sample Input and Output: Purchase Order
We'll use the cocoa purchase order for converting from XML to a flat file format. The particular orders we will produce for Big Daddy's system are similar to the invoices in that they contain two logical groups of records. The top-level group is the overall purchase order, containing a header record, a ship to record, and one or more line item groups. The line item
The three purchase order instance documents shown below follow the logical organization specified in Table 8.2. Sample FlatPurchaseOrders01.xml
<?xml version="1.0" encoding="UTF-8"?>
<PurchaseOrder
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="FlatPurchaseOrder.xsd">
<Header>
<CustomerNumber>BQ003</CustomerNumber>
<PONumber>AZ999345</PONumber>
<PODate>2002-11-01</PODate>
<RequestedDeliveryDate>2002-11-15</RequestedDeliveryDate>
</Header>
<ShipTo>
<ShipToName>
Yazoo Grocers - NE Distribution Center
</ShipToName>
<ShipToStreet1>12 Industrial Parkway, NW</ShipToStreet1>
<ShipToCity>Portland</ShipToCity>
<ShipToStateOrProvince>ME</ShipToStateOrProvince>
<ShipToPostalCode>04101</ShipToPostalCode>
</ShipTo>
<LineItem>
<Item>
<ItemID>HCVAN</ItemID>
<OrderedQty>12</OrderedQty>
<UnitPrice>2.59</UnitPrice>
</Item>
<ItemDescription>
<Description>
Instant Hot Cocoa Mix - Vanilla flavor
</Description>
</ItemDescription>
</LineItem>
<LineItem>
<Item>
<ItemID>HCMIN</ItemID>
<OrderedQty>24</OrderedQty>
<UnitPrice>2.53</UnitPrice>
</Item>
<ItemDescription>
<Description>
Instant Hot Cocoa Mix - Mint flavor
</Description>
</ItemDescription>
</LineItem>
</PurchaseOrder>
Table 8.2. Logical Layout for the Purchase Order
Sample FlatPurchaseOrders02.xml
<?xml version="1.0" encoding="UTF-8"?>
<PurchaseOrder
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="FlatPurchaseOrder.xsd">
<Header>
<CustomerNumber>BQ003</CustomerNumber>
<PONumber>AW999346</PONumber>
<PODate>2002-11-01</PODate>
<RequestedDeliveryDate>2002-11-15</RequestedDeliveryDate>
</Header>
<ShipTo>
<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>
<LineItem>
<Item>
<ItemID>HCVAN</ItemID>
<OrderedQty>36</OrderedQty>
<UnitPrice>2.59</UnitPrice>
</Item>
<ItemDescription>
<Description>
Instant Hot Cocoa Mix - Vanilla flavor
</Description>
</ItemDescription>
</LineItem>
<LineItem>
<Item>
<ItemID>HCMIN</ItemID>
<OrderedQty>72</OrderedQty>
<UnitPrice>2.53</UnitPrice>
</Item>
<ItemDescription>
<Description>
Instant Hot Cocoa Mix - Mint flavor
</Description>
</ItemDescription>
</LineItem>
</PurchaseOrder>
Sample FlatPurchaseOrders03.xml
<?xml version="1.0" encoding="UTF-8"?>
<PurchaseOrder
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="FlatPurchaseOrder.xsd">
<Header>
<CustomerNumber>AY001</CustomerNumber>
<PONumber>2002-0967</PONumber>
<PODate>2002-11-09</PODate>
<RequestedDeliveryDate>2002-11-14</RequestedDeliveryDate>
</Header>
<ShipTo>
<ShipToName>Corner Drug and Sundries</ShipToName>
<ShipToStreet1>14 Main Street</ShipToStreet1>
<ShipToCity>Wichita</ShipToCity>
<ShipToStateOrProvince>KS</ShipToStateOrProvince>
<ShipToPostalCode>67201</ShipToPostalCode>
</ShipTo>
<LineItem>
<Item>
<ItemID>HCVAN</ItemID>
<OrderedQty>24</OrderedQty>
<UnitPrice>2.59</UnitPrice>
</Item>
<ItemDescription>
<Description>
Instant Hot Cocoa Mix - Vanilla flavor
</Description>
</ItemDescription>
</LineItem>
</PurchaseOrder>
Figure 8.2 shows the resulting flat file. |