Sample Input and Output: Purchase Order

Following through with our simple procurement example, we'll use a purchase order as the sample document. (See Table 7.2 for the layout. Note that the Description column in this table includes a required or optional designation. This is something we'll be concerned about validating when importing into the application but not when we export from it.) We'll have several XML documents representing purchase orders from different customers, each ordering the gourmet hot chocolate mixes. We want to convert the XML documents to CSV format, in a single file, so that we can import them into our desktop bookkeeping and order management system.

Here are three purchase orders that follow this logical organization.

Sample PurchaseOrders01.xml
<?xml version="1.0" encoding="UTF-8"?>
<PurchaseOrder>
  <POLine>
    <CustomerNumber>BQ003</CustomerNumber>
    <PONumber>AZ999345</PONumber>
    <PODate>2002-11-12</PODate>
    <RequestedDeliveryDate>2002-11-15</RequestedDeliveryDate>
    <ShipToName>
      Yazoo Grocers - NE Distribution Center
    </ShipToName>
    <ShipToStreet1>12 Industrial Parkway, NW</ShipToStreet1>
    <ShipToCity>Portland</ShipToCity>
    <ShipToState>ME</ShipToState>
    <ShipToPostalCode>04101</ShipToPostalCode>
    <ItemID>HCVAN</ItemID>
    <OrderedQty>12</OrderedQty>
    <UnitPrice>2.59</UnitPrice>
    <ItemDescription>
      Instant Hot Cocoa Mix - Vanilla flavor
    </ItemDescription>
  </POLine>
  <POLine>
    <CustomerNumber>BQ003</CustomerNumber>
    <PONumber>AZ999345</PONumber>
    <PODate>2002-11-12</PODate>
    <RequestedDeliveryDate>2002-11-15</RequestedDeliveryDate>
    <ShipToName>
      Yazoo Grocers - NE Distribution Center
    </ShipToName>
    <ShipToStreet1>12 Industrial Parkway, NW</ShipToStreet1>
    <ShipToCity>Portland</ShipToCity>
    <ShipToState>ME</ShipToState>
    <ShipToPostalCode>04101</ShipToPostalCode>
    <ItemID>HCMIN</ItemID>
    <OrderedQty>24</OrderedQty>
    <UnitPrice>2.53</UnitPrice>
    <ItemDescription>
      Instant Hot Cocoa Mix - Mint flavor
    </ItemDescription>
  </POLine>
</PurchaseOrder>

Table 7.2. Logical Layout for the Purchase Order
Column NumberColumn NameData TypeDescription
1Customer NumberAlphanumericRequired; identifier assigned to the customer in our system
2PO NumberAlphanumericRequired; customer purchase order number
3PO DateDateRequired; date that the purchase order was issued
4Requested Delivery DateDateOptional; date on which delivery of the ordered items is requested
5Ship to NameAlphanumeric (delimited)Required; name of the receiving location for shipped order
6Ship to Street 1Alphanumeric (delimited)Required; first address line of the receiving location
7Ship to Street 2Alphanumeric (delimited)Optional; second address line of the receiving location
8Ship to CityAlphanumericRequired; city of the receiving location
9Ship to State or ProvinceAlphanumericRequired; state or province of the receiving location
10Ship to Postal CodeAlphanumericRequired; postal code of the receiving location
11Ship to CountryAlphanumericOptional; country of the receiving location
12Item IDAlphanumericRequired; identifier for the ordered item
13Item QuantityDecimal numberRequired; number of units ordered
14Item Unit PriceDecimal numberOptional (since price may be determined by contract); unit price in U.S. dollars
15Item DescriptionAlphanumeric (delimited)Optional; description of the ordered item

Sample PurchaseOrders02.xml
<?xml version="1.0" encoding="UTF-8"?>
<PurchaseOrder>
  <POLine>
    <CustomerNumber>BQ003</CustomerNumber>
    <PONumber>AW999346</PONumber>
    <PODate>2002-11-12</PODate>
    <RequestedDeliveryDate>2002-11-15</RequestedDeliveryDate>
    <ShipToName>
      Yazoo Grocers - SE Distribution Center
    </ShipToName>
    <ShipToStreet1>Dock 37</ShipToStreet1>
    <ShipToStreet2>3975 Hwy 75</ShipToStreet2>
    <ShipToCity>Atoka</ShipToCity>
    <ShipToState>OK</ShipToState>
    <ShipToPostalCode>74525</ShipToPostalCode>
    <ItemID>HCVAN</ItemID>
    <OrderedQty>36</OrderedQty>
    <UnitPrice>2.59</UnitPrice>
    <ItemDescription>
      Instant Hot Cocoa Mix - Vanilla flavor
    </ItemDescription>
  </POLine>
  <POLine>
    <CustomerNumber>BQ003</CustomerNumber>
    <PONumber>AW999346</PONumber>
    <PODate>2002-11-12</PODate>
    <RequestedDeliveryDate>2002-11-15</RequestedDeliveryDate>
    <ShipToName>
      Yazoo Grocers - SE Distribution Center
    </ShipToName>
    <ShipToStreet1>Dock 37</ShipToStreet1>
    <ShipToStreet2>3975 Hwy 75</ShipToStreet2>
    <ShipToCity>Atoka</ShipToCity>
    <ShipToState>OK</ShipToState>
    <ShipToPostalCode>74525</ShipToPostalCode>
    <ItemID>HCMIN</ItemID>
    <OrderedQty>72</OrderedQty>
    <UnitPrice>2.53</UnitPrice>
    <ItemDescription>
      Instant Hot Cocoa Mix - Mint flavor
    </ItemDescription>
  </POLine>
</PurchaseOrder>

Sample PurchaseOrders03.xml
<?xml version="1.0" encoding="UTF-8"?>
<PurchaseOrder>
  <POLine>
    <CustomerNumber>AY001</CustomerNumber>
    <PONumber>2002-0967</PONumber>
    <PODate>2002-11-12</PODate>
    <RequestedDeliveryDate>2002-11-14</RequestedDeliveryDate>
    <ShipToName>Corner Drug and Sundries</ShipToName>
    <ShipToStreet1>14 Main Street</ShipToStreet1>
    <ShipToCity>Wichita</ShipToCity>
    <ShipToState>KS</ShipToState>
    <ShipToPostalCode>67201</ShipToPostalCode>
    <ItemID>HCVAN</ItemID>
    <OrderedQty>24</OrderedQty>
    <UnitPrice>2.59</UnitPrice>
    <ItemDescription>
      Instant Hot Cocoa Mix - Vanilla flavor
    </ItemDescription>
  </POLine>
</PurchaseOrder>

Successful processing of these three documents should produce a CSV file that looks like the one shown below. (Note: Line breaks and indentation have been inserted for readability.)

Sample Output CSV File
BQ003,AZ999345,11/12/2002,11/15/2002,
 "Yazoo Grocers - NE Distribution Center",
 "12 Industrial Parkway, NW",,"Portland",ME,04101,,
 HCVAN,12,2.59,"Instant Hot Cocoa Mix - Vanilla flavor"
BQ003,AZ999345,11/12/2002,11/15/2002,
 "Yazoo Grocers - NE Distribution Center",
 "12 Industrial Parkway, NW",,"Portland",ME,04101,,
 HCMIN,24,2.53,"Instant Hot Cocoa Mix - Mint flavor"
BQ003,AW999346,11/12/2002,11/15/2002,
 "Yazoo Grocers - SE Distribution Center",
 "Dock 37","3975 Hwy 75","Atoka",OK,74525,,
 HCVAN,36,2.59,"Instant Hot Cocoa Mix - Vanilla flavor"
BQ003,AW999346,11/12/2002,11/15/2002,
 "Yazoo Grocers - SE Distribution Center",
 "Dock 37","3975 Hwy 75","Atoka",OK,74525,,
 HCMIN,72,2.53,"Instant Hot Cocoa Mix - Mint flavor"
AY001,2002-0967,11/12/2002,11/14/2002,
 "Corner Drug and Sundries",
 "14 Main Street",,"Wichita",KS,67201,,
 HCVAN,24,2.59,"Instant Hot Cocoa Mix - Vanilla flavor"

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset