Using DFDL schema CSV_1

This DFDL schema, CSV_1.xsd, illustrates the simplest model for a comma separated value message. The sample input data, CSV_1.csv, contains a repeating, comma separated record. The sample input data is parsed by using the sample DFDL schema file, a mapping node copies the DFDL domain logical structure tree to an XMLNSC domain tree, and this tree is serialized as an XML message.

This topic includes instructions for running the sample. It also includes sample input data and an expected output message, so you can confirm the sample has worked.

For a more detailed explanation of the message model that is used in this sample, see Exploring the Comma Separated Value (CSV) sample.

If you encounter any problems when you run the sample, see Resolving problems when running samples in the WebSphere Message Broker documentation.

Test DFDL schema CSV_1

You can test the sample input data against the DFDL schema file by using the Message Broker Toolkit.

To test the DFDL schema file:

  1. Open the DFDL schema, CSV_1.xsd.
  2. Under Message Roots, right-click CSV_1. Click Test Parse Model.
  3. In the Test Parse Model window, select Content from a data file, click Browse.
  4. In the File Selection window, under the Message Broker Project, CSVSchemas, select the file CSV_1.csv. Click OK.
  5. A window may be displayed that asks you if you want to open the DFDL Test perspective. Click Yes.

The DFDL Test perspective opens, and the results of your test-parse are displayed in the DFDL Test - Parse view. If the test parse is successful, a message will appear that states, "Parsing completed successfully".

You can view the results of your test-parse in the Logical Instance view. The Logical Instance view displays data in a logical tree view. Use the parser log in the DFDL - Trace view to view any errors that occurred during parsing.

Input test message

The test message that is used in running this sample is based on the following format:

Bob,Dyson,true,23,23456,0,1543543.36<CRLF>
Jimmy,Pace,false,1002,10001,-4.32423,654654.99<CRLF>
Ralf,McCartney,false,67,89125,4324307.35,986545.12<CRLF>
Elvis,John,true,3,60699,-0.343242356675,99999999999999.99<CRLF>
Rick,Clayton,true,461,33101,0.000000000000001,100.01
<CRLF> represents the characters with ASCII hex code points x'0D' and x'0A'.

Running the sample

This sample uses the message flow, CSV2XML. This message flow contains a single MQInput node attached to the queue, CSV2XML.IN1. The message flow passes the message through a Mapping node that changes the domain to XMLNSC and puts the message to the queue CSV2XML.OUT1. The output XML message shows the logical structure of the message that was parsed.

To run the sample:

  1. In the Broker Development view, expand the Message Broker Project, CSVMessageFlows, under Flow Tests, open CSVApplication.mbtest.
  2. In the Editor view, select the entry with the label "Invoke Message flow(CSV_1 to XML)". Observe the CSV formated data.
  3. Click the Start icon in the top-left of the editor.
  4. The message flow parses the CSV message and serializes the message as XML. The output message is put to the CSV2XML.OUT queue.
  5. The message may be shown in the Viewer in a continuous line. To view the message more easily, click the Body list and select View as XML structure.
  6. Compare this message with the expected output message.

If all the steps are successful, then the sample is complete.

Now look at the DFDL schema file in the Message Broker project, CSVSchemas and the explanation of this message model in Exploring the Comma Separated Value (CSV) sample.

Expected output message

The expected output XML message is:

<io:CSV_1 xmlns:io="http://www.example.org">
  <customer>
    <firstname>Bob</firstname>
    <lastname>Dyson</lastname>
    <goldmember>true</goldmember>
    <housenumber>23</housenumber>
    <postcode>23456</postcode>
    <float>0E+0</float>
   <balance>1543543.36</balance>
  </customer><customer>
    <firstname>Jimmy</firstname>
    <lastname>Pace</lastname>
    <goldmember>false</goldmember>
    <housenumber>1002</housenumber>
    <postcode>10001</postcode>
    <float>-4.3242301940918E+0</float>
    <balance>654654.99</balance>
  </customer>
  <customer>
    <firstname>Ralf</firstname>
    <lastname>McCartney</lastname>
    <goldmember>false</goldmember>
    <housenumber>67</housenumber>
    <postcode>89125</postcode>
    <float>4.3243075E+6</float>
    <balance>986545.12</balance>
  </customer>
  <customer>
    <firstname>Elvis</firstname>
    <lastname>John</lastname>
    <goldmember>true</goldmember>
    <housenumber>3</housenumber>
    <postcode>60699</postcode>
    <float>-3.43242347240448E-1</float>
    <balance>99999999999999.99</balance>
  </customer>
  <customer>
    <firstname>Rick</firstname>
    <lastname>Clayton</lastname>
    <goldmember>true</goldmember>
    <housenumber>461</housenumber>
    <postcode>33101</postcode>
    <float>1.00000000362749E-15</float>
    <balance>100.01</balance>
  </customer>
</io:CSV_1>

Back to Running the sample

Back to sample home