XML with multiple header and body in a single file

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
skp
Premium Member
Premium Member
Posts: 135
Joined: Wed Dec 26, 2007 1:56 am
Location: India

XML with multiple header and body in a single file

Post by skp »

Hi,

I have a requirement to create a single XML output file with multiple headers. For example, if I have 3 records coming to my XML stage, then I need to have header for each record. Sample expected output format below.

<?xml version="1.0" encoding="UTF-8"?><TCRMService xmlns="http://www.ibm.com/mdm/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ibm.com/mdm/schema MDMDomains.xsd">
<body>
...
...
</body>
</TCRMService>
<?xml version="1.0" encoding="UTF-8"?><TCRMService xmlns="http://www.ibm.com/mdm/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ibm.com/mdm/schema MDMDomains.xsd">
<body>
...
...
</body>
</TCRMService>
<?xml version="1.0" encoding="UTF-8"?><TCRMService xmlns="http://www.ibm.com/mdm/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ibm.com/mdm/schema MDMDomains.xsd">
<body>
...
...
</body>
</TCRMService>

Note:
<body>.....</body> contains few elements which are common to all the records with different values.

Current job design is as follows:
File -> Tfm -> xml output stage.

In XML output stage, I have checked Transfomation Settings option to "Aggregate All rows" without checking "Generate XML chunk" option.

With the above setting, I am able to generate the XML file with 1 header and multiple body. Can you please help me to achieve the above requirement.

Thanks for you help in advance.
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

You need to fully release the xml for each group of incoming rows that define a whole body. Set up a sort key and put the incoming rows in the order by each desired body and then use trigger column to identify that sort key. It doesnt have to be a column you are using in the xml. Make the output link one large column, longvarchar with a single / in the Dscription. Go to a sequential stage with None for delimiter and quote character.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
skp
Premium Member
Premium Member
Posts: 135
Joined: Wed Dec 26, 2007 1:56 am
Location: India

Post by skp »

eostic wrote:You need to fully release the xml for each group of incoming rows that define a whole body. Set up a sort key and put the incoming rows in the order by each desired body and then use trigger column ...
I tried it, but i am still not getting the proper result.
Below is my understanding, Please clarify me if i have understood wrongly.

1) I have made one of the key field which will be unique.
2) I have released the whole group ..i.e i am not creating it is in chunk.
3) I am using the Keyfield as trigger column.

Below is my sample output XML file.

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?> 
- <TCRMService xmlns="http://www.ibm.com/mdm/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ibm.com/mdm/schema MDMDomains.xsd">
- < RequestControl>
      <requestID>2016100418</requestID> 
-    <DWLControl>
         <requesterName>Delta_TBL</requesterName> 
         <requesterLocale>en</requesterLocale> 
         <transactionCorrelatorId>2016100418</transactionCorrelatorId> 
         <clientSystemName>GIW</clientSystemName> 
         <updateMethodCode>Delta</updateMethodCode> 
   </DWLControl>
  </RequestControl>
- <TCRMTx>
  < TCRMTxType>maintainAOCMCustomerProfile</TCRMTxType> 
  < TCRMTxObject>AOCMPartyWrapperRequestBObj</TCRMTxObject> 
- < TCRMObject>
- <    AOCMPartyWrapperRequestBObj>
- <      AOCMPartyFinderBObj>
  <         ReferenceNumber>902194899</ReferenceNumber> 
  <         ReferenceType>CAP</ReferenceType> 
    </AOCMPartyFinderBObj>
-  <TCRMFSPartyBObj>
-    <TCRMPersonBObj>
-     <TCRMPartyValueBObj>
         <PartyId>712433483834197586</PartyId> 
         <EntityName>CONTACT</EntityName> 
         <PartyValueType>100001</PartyValueType> 
         <SourceIdentType>100004</SourceIdentType> 
         <Attribute0Type>100001</Attribute0Type> 
         <Attribute0String>999999.99</Attribute0String> 
         <Attribute1Type>100002</Attribute1Type> 
         <Attribute1String>888888.88</Attribute1String> 
         <Attribute2Type>100003</Attribute2Type> 
         <Attribute2String>777777.77</Attribute2String> 
   </TCRMPartyValueBObj>
  </TCRMPersonBObj>
  </TCRMFSPartyBObj>
  </AOCMPartyWrapperRequestBObj>
  </TCRMObject>
  </TCRMTx>
  </TCRMService>
This is sample for 1 record & I am expecting the same structure for each incoming records.
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

....probably you should not be using the aggregate option, and also, as noted earlier, do not let the xmlOutput stage do the i/o.....send an output link down to a seq stage.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
skp
Premium Member
Premium Member
Posts: 135
Joined: Wed Dec 26, 2007 1:56 am
Location: India

Post by skp »

Hi ,

Thanks alot, Solution worked and i am able to create the records in required format.


I am not sure why i am getting the " for double quotes inside the namespace. Please suggest me how to get get the double quotes. Issue is only with namespace.



Let me give the options what i used.


Seq stage ---> transformor--> xml output stage --> Seq stage

In XML output stage , below are the changes

1) in output tab checked
a) replace nulls to empty
b) open and close tag
c) use Trigger column ( Column name reference no)
d) columns passed ---> only the high level i.e TCRMService.
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

Congrats on getting it all to work. On your quotes, its hard to say, but before you worry about it, copy "one" single document from your file (your file is now a collection of many xml documents, one per row), and put it into a file by itself, with suffix of .xml. Open it in your browser to see if it opens successfully, with color parsing and indentation. If so, it is valid.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
skp
Premium Member
Premium Member
Posts: 135
Joined: Wed Dec 26, 2007 1:56 am
Location: India

Post by skp »

Thanks alot Ernie...!! When i take only one record and view in IE ....Its perfect record..!!

Unfortunately ... i need to send the xml file to downstream and they are not able to read the file.

When they modified the file to have " instead of " they were able to process the file.

Hope a some minute changes is required... Just need to figure it out.
Post Reply