How do you string a series of xml records together ?

Formally known as "Mercator Inside Integrator 6.7", DataStage TX enables high-volume, complex transactions without the need for additional coding.

Moderators: chulett, rschirm

jazzer1
Participant
Posts: 37
Joined: Mon Mar 20, 2006 10:26 am

How do you string a series of xml records together ?

Post by jazzer1 »

I have a group of xml records....

<rec>111</rec>
<rec>222</rec>
<rec>333</rec>
<rec>444</rec>
<rec>555</rec>

I can extract them, but I want to string them together like this....

<rec>111</rec><rec>222</rec><rec>333</rec><rec>444</rec>>rec>555</rec>

Any help is appreciated.
Thanks.
janhess
Participant
Posts: 201
Joined: Thu Sep 18, 2003 2:18 am
Location: UK

Post by janhess »

you could have an output card with an item that occurs S and has no terminator. Put a functional map in the rule like f_string(package(recin)) and in the functional map move the input card to the output card.
jazzer1
Participant
Posts: 37
Joined: Mon Mar 20, 2006 10:26 am

Post by jazzer1 »

If I did this the way you said, it didn't have any impact.
My input is a group with many records and no delimiters.
My output rule is =F_String(PACKAGE(DummyRec:Input01)).

The output still comes out like this:

<rec>111</rec>
<rec>222</rec>
<rec>333</rec>
<rec>444</rec>
<rec>555</rec>

Even though my input file looks like xml, is it possible that I should treat
it as a flat file ? I'm new at this, no training yet. Thanks for your help.
I intend to keep experimenting.
janhess
Participant
Posts: 201
Joined: Thu Sep 18, 2003 2:18 am
Location: UK

Post by janhess »

looks like you've got a CR LF in your input.
you could use
F_String(substitute(PACKAGE(DummyRec:Input01),"<CR><LF",""))

Make sure you don't have a CR LF on your output card group or item.
jazzer1
Participant
Posts: 37
Joined: Mon Mar 20, 2006 10:26 am

Post by jazzer1 »

WOW ! That certainly changed the output. That's much closer to my end result. It's amazing what a little help can do.
Thanks tons for your help.
janhess
Participant
Posts: 201
Joined: Thu Sep 18, 2003 2:18 am
Location: UK

Post by janhess »

oops missed > from the end ot the LF.
Should be
F_String(substitute(PACKAGE(DummyRec:Input01),"<CR><LF>",""))
boblopez1
Participant
Posts: 15
Joined: Fri Mar 10, 2006 1:34 pm
Location: Pennsylvania

Post by boblopez1 »

jazzer1 wrote:If I did this the way you said, it didn't have any impact.
My input is a group with many records and no delimiters.
My output rule is =F_String(PACKAGE(DummyRec:Input01)).

The output still comes out like this:

<rec>111</rec>
<rec>222</rec>
<rec>333</rec>
<rec>444</rec>
<rec>555</rec>

Even though my input file looks like xml, is it possible that I should treat
it as a flat file ? I'm new at this, no training yet. Thanks for your help.
I intend to keep experimenting.

Actually you may want to try a much simpler way the use of PACKAGE will pass along the initiator and terminator of the record you can use TEXT instead which leaves out the initiator and terminator.

Well that's my .2 cents worth. :-)
janhess
Participant
Posts: 201
Joined: Thu Sep 18, 2003 2:18 am
Location: UK

Post by janhess »

However, if the xml tags are the initiator and terminator you won't get them so you'll only get the data.
jazzer1
Participant
Posts: 37
Joined: Mon Mar 20, 2006 10:26 am

Post by jazzer1 »

I was actually able to string the data together by doing this:

=LEAVEPRINT(DummyRecs)

I used this against the group and did not need the F_Map. I just got
lucky and stumbled into this command thanks to JanHess pointing me
in the right direction.

The new twist is that the xml tags are not consistent. Anything between
<abc> and </abc> is game.

So the input is:
<abc>
<rec>111</rec>
<dddec>222</dddrec>
<xrec>333</xrec>
<sss>444</sss>
</abc>

And the output has to be:

111|222|333|444 etc.

Thanks all for your help.
boblopez1
Participant
Posts: 15
Joined: Fri Mar 10, 2006 1:34 pm
Location: Pennsylvania

Post by boblopez1 »

jazzer1 wrote:I was actually able to string the data together by doing this:

=LEAVEPRINT(DummyRecs)

I used this against the group and did not need the F_Map. I just got
lucky and stumbled into this command thanks to JanHess pointing me
in the right direction.

The new twist is that the xml tags are not consistent. Anything between
<abc> and </abc> is game.

So the input is:
<abc>
<rec>111</rec>
<dddec>222</dddrec>
<xrec>333</xrec>
<sss>444</sss>
</abc>

And the output has to be:

111|222|333|444 etc.

Thanks all for your help.
Great, glad that works for you, did you try TEXT, cause I believe that would have given you the same result , reason being that TEXT would be the correct funtion to use in that scenario.

Have a great day.
jazzer1
Participant
Posts: 37
Joined: Mon Mar 20, 2006 10:26 am

Post by jazzer1 »

I guess I said that wrong.....I still need to figure out how to strip the xml
tags from the data.

I can do this:
<abc><rec>111</rec><dddec>222</dddrec><xrec>333</xrec> etc.


But not this:
111|222|333|444 etc.

Any suggestions ?

Thank you all very much.
boblopez1
Participant
Posts: 15
Joined: Fri Mar 10, 2006 1:34 pm
Location: Pennsylvania

Post by boblopez1 »

jazzer1 wrote:I guess I said that wrong.....I still need to figure out how to strip the xml
tags from the data.

I can do this:
<abc><rec>111</rec><dddec>222</dddrec><xrec>333</xrec> etc.


But not this:
111|222|333|444 etc.

Any suggestions ?

Thank you all very much.
The use of TEXT will remove the Tags from the Record Object only, now if you want the tags to be removed from the individual fields you can:

A) Change the output type tree to define each individual field without initiators or terminators and then map each field seperately which will give you what you want.
B) If you are mapping the XML rec to a Text BLOB you may consider contatenating =TEXT(field1)+TEXT(field2)+TEXT(field3)+etc. Again the TEXT will remove the tags since they are defined as initiators and terminators, do not use PACKAGE.

That's all I got for now, I'm working on a map right now but If I get a chance to try something on my end, I will respond back. give the concat a try if your not dealing with too many fields but I believe that may work, faster than defining a whole record as I suggested in A).

Kind Regards,
Bob Lopez
boblopez1
Participant
Posts: 15
Joined: Fri Mar 10, 2006 1:34 pm
Location: Pennsylvania

Post by boblopez1 »

Unfortunetly the functions SUBSTITUTE and/or SQUEEZE will not work because the tags are not consistent. If the tags were consistent such as <data1><data2><data3> like a delimiter than you can use SUBSTITUTE or if they were pairs like HEX pairs <<>> then you can use SQUEEZE, try concatenate with TEXT again this should work.

Kind Regards,
Bob
jazzer1
Participant
Posts: 37
Joined: Mon Mar 20, 2006 10:26 am

Post by jazzer1 »

I have just discovered that for now the tags are consistent...
<data1>1111</data1>
<data2>2222</data2>
<data3>3333</data3>
<data4>4444</data4>

etc...

The end result should be : 1111|2222|3333|4444

Thank you as always.
jgibby
Participant
Posts: 42
Joined: Thu Dec 16, 2004 8:48 am

Post by jgibby »

Have you tried the SERIESTOTEXT function?

Code: Select all

=SERIESTOTEXT(DummyRec:Input01+"|")
Hopefully, this would produce your desired result of:

1111|2222|3333|4444|

You might need to remove the trailing pipe though. I don't have time to check it out this morning. Let us know if it works.

John
Post Reply