This sample builds on sample 8 to include a choice of two different types of customer record in the CSV message. It illustrates that with a tagged model this can be done easily and has a model where any number of the different types of record can occur in any order. In the input message there is a single header record followed by a single repeating comma separated record followed by a single trailer record. This is parsed using the sample message set and written as an XML message.
This topic includes instructions for running the sample. It also includes an example of an input test message and a corresponding expecgted output message, so that you can confirm that the sample has worked.
For a more detailed explanation of the message model used in this sample please refer to Exploring the Comma Separated Value (CSV) sample.
The test message used in running this sample is based on the following format:
HEADER,2005-04-01,X123456IB7,customer details<CRLF>
IND,Bob,Dyson,1 Desolation Row,Orlando,FL,32802,HYT-457-AX<CRLF>
IND,Jimmy,Pace,1002 Misty Mountain Drive,New York,NY,10001,ADU-239-BX<CRLF>
IND,Ralf,McCartney,67 Penny Lane,Las Vegas,NV,89125,JUI-854-CF<CRLF>
IND,Elvis,John,3 Yellow Brick Road,Chicago,IL,60699,GGY-118-AS<CRLF>
BUS,USA.COM,1600 Pennsylvania Avenue,Washington,DC,20500,MAD-444-IT<CRLF>
IND,Rick,Clayton,461 Ocean Boulevard,Miami,FL,33101,LOP-212-TY<CRLF>
TRAILER,6
<CRLF> represents the characters with ASCII hex code points x'0D' and x'0A'.
This sample uses the message flow CSV2XML. It contains many input nodes but for this sample it uses the node with the queue called CSV2XML.IN9. The message flow passes the message through a compute node that changes the format to XML and writes the message out. This causes the CSV message to be parsed into a logical tree and then written in XML format. The output XML message shows the logical structure of the message that was parsed.
To run the sample:
The message flow parses the CSV message and writes out the same logical message in XML. A message should appear on the CSV2XML.OUT queue.
Now try repeating steps 2-6, using the XML_msg9.enqueue file (which contains the same XML message output by the first flow) and XML2CSV.IN and XML2CSV.OUT as the two queues. This passes the XML message through the reverse flow of that used in the first stage resulting in a CSV message as output. Compare this with the original CSV message. They should be identical.
If all the steps have worked then the sample is complete.
Now take a look at the message set project and the explanation of this message definition in Exploring the Comma Separated Value (CSV) sample.
The expected output XML message is:
<?xml version="1.0"?>
<CSV_9>
<header>
<requestDate>2005-04-01</requestDate>
<requestID>X123456IB7</requestID>
<requestType>customer details</requestType>
</header>
<individualCustomer>
<firstname>Bob</firstname>
<lastname>Dyson</lastname>
<streetaddress>1 Desolation Row</streetaddress>
<cityname>Orlando</cityname>
<statecode>FL</statecode>
<postcode>32802</postcode>
<referencecode>HYT-457-AX</referencecode>
</individualCustomer>
<individualCustomer>
<firstname>Jimmy</firstname>
<lastname>Pace</lastname>
<streetaddress>1002 Misty Mountain Drive</streetaddress>
<cityname>New York</cityname>
<statecode>NY</statecode>
<postcode>10001</postcode>
<referencecode>ADU-239-BX</referencecode>
</individualCustomer>
<individualCustomer>
<firstname>Ralf</firstname>
<lastname>McCartney</lastname>
<streetaddress>67 Penny Lane</streetaddress>
<cityname>Las Vegas</cityname>
<statecode>NV</statecode>
<postcode>89125</postcode>
<referencecode>JUI-854-CF</referencecode>
</individualCustomer>
<individualCustomer>
<firstname>Elvis</firstname>
<lastname>John</lastname>
<streetaddress>3 Yellow Brick Road</streetaddress>
<cityname>Chicago</cityname>
<statecode>IL</statecode>
<postcode>60699</postcode>
<referencecode>GGY-118-AS</referencecode>
</individualCustomer>
<businessCustomer>
<businessname>USA.COM</businessname>
<streetaddress>1600 Pennsylvania Avenue</streetaddress>
<cityname>Washington</cityname>
<statecode>DC</statecode>
<postcode>20500</postcode>
<referencecode>MAD-444-IT</referencecode>
</businessCustomer>
<individualCustomer>
<firstname>Rick</firstname>
<lastname>Clayton</lastname>
<streetaddress>461 Ocean Boulevard</streetaddress>
<cityname>Miami</cityname>
<statecode>FL</statecode>
<postcode>33101</postcode>
<referencecode>LOP-212-TY</referencecode>
</individualCustomer>
<trailer>
<totalRecords>6</totalRecords>
</trailer>
</CSV_9>