This sample builds on sample 4 to add basic support for CSV style quoted escaping of string fields. So reserved characters like comma (,) can be used in data. This sample parses fields with or without quotes and supports comma in the data for quoted fields. It retains the quotes as part of the business data and does not support use of quotes in quoted data. For a more complete and complex treatment of CSV quoted escaping then see sample 6 and sample 7. 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 Seaprated Value (CSV) sample.
The test message used in running this sample is based on the following format:
2005-04-01,X123456IB7,customer details<CRLF>
Bob,Dyson,"House of the Rising Sun, 1, Desolation Row",Orlando,FL,32802,HYT-457-AX<CRLF>
Jimmy,Pace,"1002, Misty Mountain Drive",New York,NY,10001,ADU-239-BX<CRLF>
Ralf,McCartney,67 Penny Lane,Las Vegas,NV,89125,JUI-854-CF<CRLF>
Elvis,John,3 Yellow Brick Road,Chicago,IL,60699,GGY-118-AS<CRLF>
Rick,Clayton,"461, Ocean Boulevard",Miami,FL,33101,LOP-212-TY<CRLF>
5
<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.IN5. 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:
Now try repeating steps 2-6, using the XML_msg5.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 Seaprated Value (CSV) sample.
The expected output XML message is:
<?xml version="1.0"?>
<CSV_5>
<header>
<requestDate>2005-04-01</requestDate>
<requestID>X123456IB7</requestID>
<requestType>customer details</requestType>
</header>
<customer>
<firstname>Bob</firstname>
<lastname>Dyson</lastname>
<streetaddress>"House of the Rising Sun, 1, Desolation Row"</streetaddress>
<cityname>Orlando</cityname>
<statecode>FL</statecode>
<postcode>32802</postcode>
<referencecode>HYT-457-AX</referencecode>
</customer>
<customer>
<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>
</customer>
<customer>
<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>
</customer>
<customer>
<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>
</customer>
<customer>
<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>
</customer>
<trailer>
<totalRecords>5</totalRecords>
</trailer>
</CSV_5>