Problem with XML output format

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
dscon9128
Participant
Posts: 25
Joined: Fri Jun 13, 2008 9:11 am

Problem with XML output format

Post by dscon9128 »

Hello,

I am new to xml and i have a problem with the xml output format which i have been unable to resolve. I have been trying to use the xml output stage to achieve my end result.

I need the follwoing output format :
<Address1>
<localeData locale ="USA">value</localeData>
</Address1>

I guess this can be achieved by providing the xpath as
Column ------ Xpath expression

locale ---------> /Address1/localeData/@locale

Address1 ---------> /Address1/localeData/text()

For now, the locale field can take the values of USA or a blank, and the address1 field can take on an address value or a blank. When the locale is USA(not a blank which means the record has a valid location address) and the address1 field has an adrress desrciption (not a blank, which means the record has a valid address), the xpath gives me what i require.

From the above xpath expression it will follow that when the locale and the address1 is blank (not a valid address) , the format is going to look like :
<Address1>
<localeData locale =""></localeData>
</Address1>

However, what i need is the following when there's no valid address loctaion .

<Address1>
</Address1>

or <Address1/> (single tag option) which is to say the attribute should not show up.

Is there anyway to code this in DS using the output stage?

I would appreciate any help greatly.

Thanks!
uegodawa
Participant
Posts: 71
Joined: Thu Apr 27, 2006 12:46 pm

Post by uegodawa »

Open the properties of XML output stage. Go to the 'Transformation Setting' tab. There are two check boxes for
* Replace NULLs with empty values
* Replace empty values with NULLs

I guess in your case you need to check the first check box. If this didn't work uncheck this and check the second one. Either case this should work.
Thanks,
Upul
uegodawa
Participant
Posts: 71
Joined: Thu Apr 27, 2006 12:46 pm

Post by uegodawa »

Open the properties of XML output stage. Go to the 'Transformation Setting' tab. There are two check boxes for
* Replace NULLs with empty values
* Replace empty values with NULLs

I guess in your case you need to check the second check box. If this didn't work uncheck this and check the first one. Either case this should work.
Thanks,
Upul
dscon9128
Participant
Posts: 25
Joined: Fri Jun 13, 2008 9:11 am

Post by dscon9128 »

[quote="uegodawa"]Open the properties of XML output stage. Go to the 'Transformation Setting' tab. There are two check boxes for
* Replace NULLs with empty values
* Replace empty values with NULLs

I guess in your case you need to check the second check box. If this didn't work uncheck this and check the first one. Either case this should work.[/quote]

Thanks for the response Upul. I tried playing around with the checkboxes like you suggested but did not get the format i was hoping to get!
As i mentioned earlier, the issue was with formatting the blanks the appropriate way.

When i checked the replace NULLS with empty values option,i get
<Address1>
<localeData locale=""/>
</Address1>
in the case of the locale = blank records.
(I would require <Address1></Address1> or <Address1/> as my format.I have defined a blank field in the source as '' which is open single quote,close single quote.I am not sure if this could be an issue.)

When i checked the replace empty values with NULLS option,
the entire address1 tag disappears i.e it does not get displayed on the output.


Am i missing something?Please advice!

Thank you for your time.
uegodawa
Participant
Posts: 71
Joined: Thu Apr 27, 2006 12:46 pm

Post by uegodawa »

Did you tried with SetNull() in your source fields for blankcolumns instead of '' (single quote, single quote)?
Thanks,
Upul
uegodawa
Participant
Posts: 71
Joined: Thu Apr 27, 2006 12:46 pm

Post by uegodawa »

Did you tried with SetNull() in your source fields for blankcolumns instead of '' (single quote, single quote)?
Thanks,
Upul
dscon9128
Participant
Posts: 25
Joined: Fri Jun 13, 2008 9:11 am

Post by dscon9128 »

Thanks for the suggestion Upul. I changed my incoming source fields to hold null by using setnull() as opposed to '' as I had previously(open single quote,close single quote).I still get the same output format as I posted above ! I basically tried only with option 1 of the transformation setting , only with option 2 and then included both even.

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

Post by eostic »

I haven't tried this exact combination lately (desire to remove an attribute when the value is null), but it's possible that there is no combination that will work. If it were a sub-element, the default would be fine......here are some other things to try....

a) are you certain that the value really "is" null? send the value to another column on your link, and do an isNull() test on it. Make it "YES" if it is null, so you can be sure at least that the behavior is happening as it should be.

b) consider building this particular element yourself in a derivation. There are times I've found that I simply need to own all the control. Just build the entire string, concatenating values and tags as needed, if the values are null or if they aren't. Won't be too hard, provided you don't have 200 of these such columns and attributes.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
dscon9128
Participant
Posts: 25
Joined: Fri Jun 13, 2008 9:11 am

Post by dscon9128 »

Thanks for your time Ernie!

Like you mentioned , I worked around it. I built the tags manually in a transformer(provided an attribute IF there was a value, else closed tags) and passed it to the XML outputWell, i just hoped that there would be a direct way to use the XML output or an XML transformer to do it. Then again im fairly new to XML and DS, so i cant hope for anything better now.
Post Reply