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 group consists of a line item record and an item description record. Table 8.2 shows the logical layout of the purchase order file.

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
GroupRecordRecord TagField NumberField NameOffsetLengthData TypeDescription
POHeaderHDR1Record Tag03AlphanumericRequired; record identifier
   2Customer Number320AlphanumericRequired; identifier assigned to the customer in our system
   3PO Number2320AlphanumericRequired; customer purchase order number
   4PO Date438DateRequired; date that the purchase order was issued
   5Requested Delivery Date518DateOptional; date on which delivery of the ordered items is requested
POShip ToSHP1Record Tag03AlphanumericRequired; record identifier
   2Ship to Name340AlphanumericRequired; name of the receiving location for the shipped order
   3Ship to Street 14330AlphanumericRequired; first address line of the receiving location
   4Ship to Street 27330AlphanumericOptional; second address line of the receiving location
   5Ship to City10320AlphanumericRequired; city of the receiving location
   6Ship to State or Province1233AlphanumericRequired; state or province of the receiving location
   7Ship to Postal Code12610AlphanumericRequired; postal code of the receiving location
   8Ship to Country1363AlphanumericOptional; country of the receiving location
PO/Line ItemLine ItemLIN1Record Tag03AlphanumericRequired; record identifier
   2Item ID320AlphanumericRequired; our identifier for the ordered item
   3Item Ordered Quantity2310Decimal number, space filledRequired; the number of units ordered
   4Item Unit Price2310Implied decimal, two places, zero filledOptional; unit price in U.S. dollars
   5Extended Amount4310Implied decimal, two places, zero filledOptional; total amount due for the ordered item in U.S. dollars (unit price multiplied by the quantity ordered)
PO/Line ItemItem DescriptionDSC1Record Tag03AlphanumericRequired; record identifier (record itself is optional)
   2Description380AlphanumericRequired; description of the ordered item

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.

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

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