in XMLoutput stage more than one repeat element

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

thumati.praveen
Participant
Posts: 106
Joined: Wed Oct 04, 2006 5:21 am

in XMLoutput stage more than one repeat element

Post by thumati.praveen »

Hi ,

Can I use more than one repeat(key column) element in xml output stage under input columns tab?

Example:-
input:-
PORD1,DETAL1
PROD2,DETAIL2
PROD3,DETAIL3



Actual Getting output:-

<IDOC>
<PROD_HEADER>xyz</PROD_HEADER>
<PROD1>
<DETAIL1>
</DOC>
<IDOC>
<PROD_HEADER>xyz</PROD_HEADER>
<PROD2>
<DETAIL2>
</DOC>
<IDOC>
<PROD_HEADER>xyz</PROD_HEADER>
<PROD3>
<DETAIL3>
</DOC>


Required output:-

<IDOC>
<PROD_HEADER>xyz</PROD_HEADER>
<PROD1>
<DETAIL1>
<PROD2>
<DETAIL2>
<PROD3>
<DETAIL3>
</IDOC>

How can I get all product details in single IDOC with single <PROD_HEADER> tag.If I select both PROD and DETAIL column as a keys in xml output stage it is coming in different IDOCs.If any body have thoughts please suggest me.

Thanks,
Praveen.
Pagadrai
Participant
Posts: 111
Joined: Fri Dec 31, 2004 1:16 am
Location: Chennai

Re: in XMLoutput stage more than one repeat element

Post by Pagadrai »

Hi,
what is the Xpath you have given for the columns ?

one try - what if you dont give the key columns ?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Short answer - no. Only one repeating / key element. That's not to say you can't generate these as 'chunks' and then assemble the chunks into the complete output format that you need after that. The Best Practices document uploaded at Kim Duke's website details this technique.
-craig

"You can never have too many knives" -- Logan Nine Fingers
thumati.praveen
Participant
Posts: 106
Joined: Wed Oct 04, 2006 5:21 am

Post by thumati.praveen »

Hi Pagadari,
If I give one key column actual results I poseted in my original post.

If dont give any key it will repeat entire xml doc.


Hi Chulett,
you mean to say generate individul chunks and assemble these chunks into main stream right?

Could you please clarify me?

Thanks,
Praveen.
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

There seems to be a conflict here of "rows" vs "columns". Is PORD1 a column name, or a value in a row? Right now, these are listed as individual and unique items --- but they are on separate rows. If indeed you just want all six elements in the same repeating group, then put them into the same repeating "row" for each prod_header:

prod1 detail1 prod2 detail2 prod3 detail3

Otherwise, are these really "values" for two columns, <PROD> and <DETAIL>.......

Please be explicit in your example...this info is key to figuring out the output that you need. XMLOutput is very dependent upon the structure and organization of the incoming rows and the way that they repeat.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
thumati.praveen
Participant
Posts: 106
Joined: Wed Oct 04, 2006 5:21 am

Post by thumati.praveen »

eostic wrote:There seems to be a conflict here of "rows" vs "columns". Is PORD1 a column name, or a value in a row? Right now, these are listed as individual and unique items --- but they are on separate rows. If indeed you just want all six elements in the same repeating group, then put them into the same repeating "row" for each prod_header:

prod1 detail1 prod2 detail2 prod3 detail3

Otherwise, are these really "values" for two columns, <PROD> and <DETAIL>.......

Please be explicit in your example...this info is key to figuring out the output that you need. XMLOutput is very dependent upon the structure and organization of the incoming rows and the way that they repeat.

Ernie
Hi,

PROD1,DETAIL1 are the values not columns names.

Exact output would be expecting is:

<IDOC>
<PROD_HEADER>xyz..</PROD_HEADER>
<PROD>PROD1</PROD>
<DETAIL>DETAIL1</DETAIL>
<PROD>PROD2</PROD>
<DETAIL>DETAIL2</DETAIL>
<PROD>PROD3</PROD>
<DETAIL>DETAIL3</DETAIL>
</IDOC>

We are getting output in the following way:
<IDOC>
<PROD_HEADER>xyz..</PROD_HEADER>
<PROD>PROD1</PROD>
<DETAIL>DETAIL1</DETAIL>
</IDOC>
<IDOC>
<PROD_HEADER>xyz..</PROD_HEADER>
<PROD>PROD2</PROD>
<DETAIL>DETAIL2</DETAIL>
</IDOC>
<IDOC>
<PROD_HEADER>xyz..</PROD_HEADER>
<PROD>PROD3</PROD>
<DETAIL>DETAIL3</DETAIL>
</IDOC>


Could you please suggest me for the expected output?

Thanks,
Praveen.
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

There are a couple of things to try...

One is to be sure that you are aggregating your rows.... second is to wrap the <prod> and <detail> elements in a compound element (for a test just put something like /test/ in the middle of the xpath statements..so where you have /.../.../.../prod/text(), make it /.../.../.../test/prod/text(), and do the same for detail.) Most times repeating groups of this kind are "contained" within an overall wrapping element, such as:

<lineitem><prod/><price/><quantity/></lineitem>

Most likely you don't want the extra element, but the result will tell us more, and/or provide a solution that is easy to implement.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

...one more thing....is it just these two columns that you are dealing with, or are many....10's or hundreds of columns?

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
thumati.praveen
Participant
Posts: 106
Joined: Wed Oct 04, 2006 5:21 am

Post by thumati.praveen »

eostic wrote:...one more thing....is it just these two columns that you are dealing with, or are many....10's or hundreds of columns?

Ernie
Hi Ernie,

Thanks for suggestions.

In my case I am having total 12 segments.For each segment I have more that 10 columns.

Example:-

<xmldoc>
<segment1>
<seg1-tag1>
<seg1-tag2>
.
.
<seg1-tag10>
</segment1>
<segment2>
<seg2-tag1>
<seg2-tag2>
.
.
<seg2-tag10>
</segment2>
<segment3>
<seg3-tag1>
<seg3-tag2>
.
.
<seg3-tag10>
</segment3>
.
.
.
.
<segment12>
<seg12-tag1>
<seg12-tag2>
.
.
<seg12-tag10>
</segment12>
</xmldoc>

In the above example segemnt1 should come only once in the xmldoc.The remining 11 segments will repeat based on how many records we are getting from source.Here my problem is exactly if I select the all 11 segments as a key column in xmloutput stage it is repeating the xmldoc for each source record.if I select the 1 segment as a key column in xmloutput stage it is also repeating the xmldoc for each source record.
The final out put I am getting is if I have 100 source records I am getting 100 xmldocs but actually requirement is one xmldoc with segement1 is one reminig 11 segment would repeat 100 times.

Could you please suggest me on the same?

Thanks,
Praveen.
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

...take a look thru the forum here, and find referecnes to the XML Best Practices doc that is at Kim Duke's site. It documents what you need to do here. Now it is more clear. XMLOutput will be able to create a single relational oriented structure for you. This means one single lowest level repeating node. If there are other independent repeating nodes (elements) at the "same" level, then you will need multiple (perhaps many) different XMLOutput Stages to put this together. If it's only a few different nodes, it's not too complex, but can get unwieldy if you have a deeply spread out hierarchy.

A single path nested hierarchy will work fine:

<rootElement>
<child>
<childDetail>
<grandchild>
<grandchildDetail>
<great grandchildTypeA>
<greatgrandchildDetail1>
<greatgrandchildDetail2>
<greatgrandchildDetail3>


But independent repeating children nodes at the same level require a mulit-stage technique:

<rootElement>
<child>
<childDetail>
<grandchild>
<grandchildDetail>
<great grandchildTypeA>
<greatgrandchildDetail1>
<greatgrandchildDetail2>
<greatgrandchildDetail3>
</greatgrandchildTypeA>
<ggTypeB>
<ggTypeBDetail>
</ggTypeB>


A real life example might be an xml document for a Customer. After customer account details, there might be a repeating node for "purchases" made by the customer in the past year. Separately, there might be a repeating node for "repair visits" that the company has made to the customer for service. Both nodes are related to customer, but repeat independently.

This is no different than having multiple relational tables to model the same thing, or a multi-path hierarchical structure in a COBOL file or VSAM/IMS when looking at legacy structures.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

...btw, I am assuming that your "segments" above are unique from each other and repeat independently (ie..you could get 2 seg1's and 1 seg3, and 4 seg7's).

...and if they aren't unique, and are really just repeating "instances" of the same thing ,why do they have unique element names?

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
thumati.praveen
Participant
Posts: 106
Joined: Wed Oct 04, 2006 5:21 am

Post by thumati.praveen »

eostic wrote:...btw, I am assuming that your "segments" above are unique from each other and repeat independently (ie..you could get 2 seg1's and 1 seg3, and 4 seg7's).

...and if they aren't unique, and are really just repeating "instances" of the same thing ,why do they have unique element names?

Ernie
Hi Ernie,

Exatly these segments are unique and these will repeat independently.

Can I get it resolve the issue?

Thanks,
Praveen.
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

I suspected as much. See if you can get what you want with just the first segment......

and then another link that goes to an xmlOutput stage that produces what you want with the second segment...

...and so forth.....

Each segment must be built independently....then hooked up later. This is usually done via lookups, but there are other techniques. See the xml best practices document that you can download at Kim Dukes site.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

The best practice is on my tricks and tips page. It is an IBM document originally posted on the old developers network. I did not write this document. I just was asked to share the document and I did. Ernie knows lots more about XML than I do.
Mamu Kim
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

We are all happy, Kim that you are the "keeper" of it ; ) I've had a copy from the day it was written, but long ago grew tired of emailing it. and.....people ought to take time to visit your site anyway....so this is a good reason to do so if they haven't already!

One of our developers wrote that document a long while ago...however, it is still current, has ideas on some great techniques, and will even give you a "little" education on xpath.

Good luck!

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
Post Reply