XML handling repetitive elements

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
frusciante
Participant
Posts: 13
Joined: Mon Mar 01, 2010 7:02 am
Location: Salerno

XML handling repetitive elements

Post by frusciante »

Hello everyone, this is my first post on this forum. So far the various wont post, I have not yet found the answer to my problem.
My question is this: In your opinion can be managed through the XML input stage and XML output stage repetitive elements?
I'm using DataStage 7.5.2 parallel.
The design of my job is:
Sequential file ---> Transformer ---> XML Output Stage
I have a text file in this format: 1-Y7X1 | Boolean | N
and I would map it into an XML file.
The output XML file that I would have, should have the following structure:

Code: Select all

<TIM>
 <outgoingAmount> 1 </ outgoingAmount>
 <ingoingAmount> 1 </ ingoingAmount>
   <Service>
      <directionality> x </ Directionality>
        <ServiceCh>
             <name> ServiceType </ name>
             <value> 1-Y7X2 </ value>
        </ ServiceCh>
        <ServiceCh>
             <name> ServiceSubType </ name>
             <value> 1-Y7X2 </ value>
        </ ServiceCh>
        <ServiceCh>
             <name> bundledID </ name>
             <value> 1-Y7X2 </ value>
         </ ServiceCh>
      <bidirectionalA> N </ bidirectionalA>
   </ Service>
 <additionalA> Boolean </ additionalA>
</ TIM>
Someone can tell me how to make the section
<ServiceCh> repetitive so as to have the xml file that I have described above?
If someone has already managed to create an XML file with repetitive elements, you could send me an export of the job?
I hope I have been clear in describing my problem. Thank you in advance.
nikhilanshuman
Participant
Posts: 58
Joined: Tue Nov 17, 2009 3:38 am

Post by nikhilanshuman »

You will have to add a dummy attribute to the tag <ServiceCh>

The tag will look like then... <ServiceCh dummy=1>

After this,the element will be repeated.

In the transformer,add a column Dummy and set its value to 1.

Now declare the XPATH for the attribute dummy.

Attribute can be declared in XPATH by using @attributename

e.g.

Tim/Service/@Dummy

Additional settings :

In the XML output stage, go to Transformation settings and make sure that the Output Mode is "Aggregate all rows"

Later,you may replace it by a meaningful attribute.

Hope this helps..
Nikhil
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

Another thing to consider is that repeating elements at the lower level are a direct reflection of "repeating rows".....so, if you have repeating rows (3 of them in this case it appears) for each of the ServiceCh elements, you will get the repeats that you are looking for. So....sometimes the technique you need is something upstream, to generate the multiple rows that you require.

Is the number of repeats "always 3"? ...or is this just an example and it could be 3, or other times 23 (for example) based on some other criteria?

...if indeed it is a need to "generate rows" upstream, I find that very easy to do in DS, and there are probably 100's of threads in this forum on how to do it. However, if the total is only "3" forever with no dynamics, then you might find it easier to just hard code this chunk of xml prior to the xml stage, and then embed it in your greater xml document, probably by using the "xml" data element when you reach the xmlOutput Stage.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
frusciante
Participant
Posts: 13
Joined: Mon Mar 01, 2010 7:02 am
Location: Salerno

Post by frusciante »

Hello Nikhilanshuman I tried to follow your advice and now I'll explain the steps that I did.
I imported the xml structure of the metadata and I used the property self-check.
In Transformer Stage I now see these fields:
http://img63.imageshack.us/img63/569/tr ... rstage.jpg

Make your changes now in Transformer Stage I have this situation:
http://img97.imageshack.us/img97/5401/t ... agemod.jpg

Once compiled and run the job, I do not get the same xml file that I showed in the first post, but I get:

Code: Select all

<TIM>
 <outgoingAmount> 1 </outgoingAmount>
 <ingoingAmount> 1 </ingoingAmount>
  <Service>
    <directionality> x </directionality>
        <ServiceCh Test="">
             <name> ServiceType </name>
             <value> 1-Y7X2 </value>
        </ServiceCh>
    <bidirectionalA> N </bidirectionalA>
  </Service>
  <additionalA> Boolean </additionalA>
</TIM>
Perhaps in the first post I have not explained exactly what I wanted to do.
I have mapped the structure <ServiceCh> several times with the <name> with defualt values, while the element <value> = value input field file.
Structure <ServiceCh> in this case is repeated 3 times.

Code: Select all

        <ServiceCh>
             <name> ServiceType </ name>
             <value> 1-Y7X2 </ value>
        </ ServiceCh>
        <ServiceCh>
             <name> ServiceSubType </ name>
             <value> 1-Y7X2 </ value>
        </ ServiceCh>
        <ServiceCh>
             <name> bundledID </ name>
             <value> 1-Y7X2 </ value>
         </ ServiceCh> 
According <ServiceCh> repetitive for you to make 3 times and to map the field <name> with 3 different values that once "ServiceType", "ServiceSubType" and "bundledID" you think that I have to create a structure on the transformer as I done in this picture :
http://img299.imageshack.us/img299/905/ ... oposta.jpg
Is correct ?
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

As noted earlier, if you need/want three repeating elements, then you need to feed in three repeating "rows". You need to have three rows...one for your Service type, one for your "subtype" and one for your bundled ID...... try it with a simple little flat file first....put each of those on a single line and read them in as separate rows. That will help illustrate the process. Then, once that is working there are tons of ways to generate the rows....pivot being one of the simplest.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
frusciante
Participant
Posts: 13
Joined: Mon Mar 01, 2010 7:02 am
Location: Salerno

Post by frusciante »

Hello Eostic the xml posted is just an example that I need to know whether or not you can handle the repetitive elements through a single XML output stage as the section that I should go to map consists of many, many more tag (about 600 items between recursive and not recursive) and is much more complex than this trivial example that I posted. Currently we for mapping XML files to use the plug-in WTX reminding us through the internship TX Maps. So basically I wanted to assess whether the use of XML Output Stage could handle this type of repetitive elements.
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

Not sure what you are looking for...the architecture for xmlOutput is that it takes multiple rows and turns them into multiple elements. That's how it works. There are lots of ways to tweak it, but this is the simplest, "by design" way to generate multiple repeating elements.

In a lot of normalized cases, there are, in fact, multiple rows for such things. In other scenarios, you might need to generate a row here and there, or manufacture the inner xml strings manually.

The real disappointment here is that the xml you are targeting wasn't better designed.... ServiceSubType and bundledID ought to be elements in their own right, within ServiceCh higher level element. Then the xml document would truly reflect the metadata, with element names = metadata, and the "value" of those elements be the string contained within them, instead of having a generic "value" element.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
frusciante
Participant
Posts: 13
Joined: Mon Mar 01, 2010 7:02 am
Location: Salerno

Post by frusciante »

Hello Ernie, then your opinion is wrong the way I thought to manage the fields as I did in this photo:http://img299.imageshack.us/img299/905/ ... oposta.jpg ???

You could kindly send me some more jobs dsx containing examples?
I'd be very much grateful.
I send you my email in a private message.
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

You are on the right track.....but what you have successfully done here is to put the other generated values into "separate columns".....what you have to do is get the other value into "multiple rows".

Create a brand new job. Create a flat file in notepad...put three rows in it:

ServiceCh, ServiceType, I-YZX2
ServiceCh, SubType,I-YZX2
ServiceCh, bundledID,I-YZX2

Be able to retrieve those three rows, and then write sample xmlOutput where you put those three rows into the structure that you are looking for. You have to play with this in tiny examples in order to appreciate the behavior.

Once you understand this, then you can go back to your first job and address ways to turn your source for these into three rows dynamically. Search the forum...there are lots of entries on pivots and similar techniques.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
frusciante
Participant
Posts: 13
Joined: Mon Mar 01, 2010 7:02 am
Location: Salerno

Post by frusciante »

Hello Ernie, thank you for your advice.
Now I try to do more research in the forum and if I can find the solution to my case I will write it in this post.
Thanks for the advice.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

If you haven't downloaded and read this... do so. A little old but still a great reference. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
frusciante
Participant
Posts: 13
Joined: Mon Mar 01, 2010 7:02 am
Location: Salerno

Post by frusciante »

Chulett Thanks :-)
I start work immediately.
Thank you.
Post Reply