|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
DFDL for csv format with key-value pair |
« View previous topic :: View next topic » |
Author |
Message
|
BBhave |
Posted: Wed Dec 12, 2018 10:10 am Post subject: DFDL for csv format with key-value pair |
|
|
Novice
Joined: 05 Dec 2018 Posts: 11
|
Hi,
I am trying to setup message model in DFDL.
My input message is csv file with key- value pair. (Key-value can come in any order.)
e.g
merchantReferenceCode=0000000000079088822017-09-0200000306915225RR,purchaseTotals_currency=usd,decision=ACCEPT
My DFDL
Code: |
<?xml version="1.0" encoding="UTF-8"?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/" xmlns:fmt="http://www.ibm.com/dfdl/GeneralPurposeFormat" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:ibmSchExtn="http://www.ibm.com/schema/extensions">
<xsd:import namespace="http://www.ibm.com/dfdl/GeneralPurposeFormat" schemaLocation="IBMdefined/GeneralPurposeFormat.xsd"/>
<xsd:element ibmSchExtn:docRoot="true" name="SFC08_PG4">
<xsd:complexType>
<xsd:sequence dfdl:separator="" dfdl:separatorSuppressionPolicy="trailingEmpty">
<xsd:element dfdl:occursCountKind="implicit" maxOccurs="unbounded" name="Detail">
<xsd:complexType>
<xsd:sequence dfdl:separator="">
<xsd:element dfdl:terminator="=" name="KeyID" type="xsd:string"/>
<xsd:choice dfdl:choiceDispatchKey="{/SFC08_PG4/Detail[1]/KeyID}" dfdl:terminator=",">
<xsd:element dfdl:choiceBranchKey="merchantReferenceCode" name="merchantReferenceCode" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://www.ogf.org/dfdl/">
<dfdl:discriminator>{/SFC08_PG4/Detail[1]/KeyID eq 'merchantReferenceCode'}</dfdl:discriminator>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element dfdl:choiceBranchKey="purchaseTotals_currency" name="purchaseTotals_currency" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://www.ogf.org/dfdl/">
<dfdl:discriminator>{/SFC08_PG4/Detail[1]/KeyID eq 'purchaseTotals_currency'}</dfdl:discriminator>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element dfdl:choiceBranchKey="decision" name="decision" type="xsd:string"/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:annotation>
<xsd:appinfo source="http://www.ogf.org/dfdl/">
<dfdl:format encoding="{$dfdl:encoding}" escapeSchemeRef="" ref="fmt:GeneralPurposeFormat"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:schema>
|
With above DFDL I achieved following message structure.
Code: |
(0x01000000:Name):DFDL = ( ['dfdl' : 0x1b7ff20]
(0x01000000:Name):SFC08_PG4 = (
(0x01000000:Name):Detail = (
(0x03000000:NameValue):KeyID = 'merchantReferenceCode' (CHARACTER)
(0x03000000:NameValue):merchantReferenceCode = '0000000000079088822017-09-0200000306915225RR' (CHARACTER)
)
(0x01000000:Name):Detail = (
(0x03000000:NameValue):KeyID = 'purchaseTotals_currency' (CHARACTER)
(0x03000000:NameValue):merchantReferenceCode = 'usd' (CHARACTER)
)
(0x01000000:Name):Detail = (
(0x03000000:NameValue):KeyID = 'decision' (CHARACTER)
(0x03000000:NameValue):merchantReferenceCode = 'ACCEPT' (CHARACTER)
|
But I was expecting as below. I also tried to use discriminator...it didn't help me.
Code: |
(0x01000000:Name):DFDL = ( ['dfdl' : 0x1b7ff20]
(0x01000000:Name):SFC08_PG4 = (
(0x01000000:Name):Detail = (
(0x03000000:NameValue):KeyID = 'merchantReferenceCode' (CHARACTER)
(0x03000000:NameValue):merchantReferenceCode = '0000000000079088822017-09-0200000306915225RR' (CHARACTER)
)
(0x01000000:Name):Detail = (
(0x03000000:NameValue):KeyID = 'purchaseTotals_currency' (CHARACTER)
(0x03000000:NameValue):purchaseTotals_currency = 'usd' (CHARACTER)
)
(0x01000000:Name):Detail = (
(0x03000000:NameValue):KeyID = 'decision' (CHARACTER)
(0x03000000:NameValue):decision = 'ACCEPT' (CHARACTER)
|
Any help would be appreciated. |
|
Back to top |
|
 |
timber |
Posted: Fri Dec 14, 2018 2:13 pm Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
Good try, but the answer is actually a lot simpler than that. Your message structure should look like this
Code: |
element name='SFC08_PG4'
complexType
sequence separator=','
element name='merchantReferenceCode' initiator='merchantReferenceCode'
element name='purchaseTotals_currency' initiator='purchaseTotals_currency='
element name='decision' initiator='decision='
|
I am purposely omitting the non-important details like element types so that the main properties are more obvious.
Note that you do not need the 'Detail' element or the 'keyID' element. The thing that you were putting into 'keyID' is not really part of the business data in the message. It's just a tag for the data. As a bonus, the message tree structure that you get from this model will be much nicer to work with than the one that you are currently getting. |
|
Back to top |
|
 |
BBhave |
Posted: Wed Dec 19, 2018 1:55 pm Post subject: |
|
|
Novice
Joined: 05 Dec 2018 Posts: 11
|
Thanks Timber!
Since my data can come in any sequence. I opted for that solution... but you are right...solution was lot simpler than that
Code: |
<xsd:sequence dfdl:separator="," dfdl:separatorSuppressionPolicy="trailingEmpty" dfdl:sequenceKind="unordered">
|
|
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|