xsi:nil+"true" in XML Output stage

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
rcanaran
Premium Member
Premium Member
Posts: 64
Joined: Wed Jun 14, 2006 3:51 pm
Location: CANADA

xsi:nil+"true" in XML Output stage

Post by rcanaran »

viewtopic.php?t=130297
viewtopic.php?t=117035
viewtopic.php?t=116064
viewtopic.php?t=10187
viewtopic.php?t=109788

I have read through the above and I am still not sure.

If I would like to set an element in the output xml to nil eg.
<colour xsi:nil="true"></colour>

Do I set the incoming element (not the xml output stage) to null using SetNull and then on the xpath statement code @xsi:nil /colour/text()
?

Also, do I need to let the xml output stage validate the xml?

I currently use 2 methods :
1) a separate job/routine to scan the output xml and update elements containing empty strings with xsi:nil="true".

or 2) in a prior transformer stage code if IsNull... then '<colour xsi:nil="true"></colour>' Else "<colour>":linkname.COLOR:"</colour>"

The client wants to use NO server jobs and NO custom built routines (no C++ routines can be used in parallel jobs).
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

For something like this, I'd do it in an upstream Derivation. Evaluate for isnull() and then create your string separately for this particular element. That way you have absolutely the most explicit control of the logic and the result. If necessary, use Data Element of "XML" in the input link of your XMLOutput Stage to be sure the string doesn't get "escaped".

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
rcanaran
Premium Member
Premium Member
Posts: 64
Joined: Wed Jun 14, 2006 3:51 pm
Location: CANADA

Post by rcanaran »

Thanks Ernie. That's actually my option 2 above. And since there are ampersands in some of the data, I have to make the element XML when passing it to the XML output stage.

The problem is that I have to do this for several jobs and many elements per job. I was hoping that, since I had imported the output definitions from an xml schema (xsd), that DS would understand this automatically and that I wouldn't have to go through the exercise of hand-coding each of these elements. Plus the potential for typos then and when the code is maintained (update element names or something like that).

Perhaps in a future release of Datastage.... maybe at the same time they release a vertical pivot. Hmmm, where is the "wishful thinking" icon ? :D
rcanaran
Premium Member
Premium Member
Posts: 64
Joined: Wed Jun 14, 2006 3:51 pm
Location: CANADA

Post by rcanaran »

Found an alternative to hand coding the xml (option 2 above). Not sure its any BETTER, just an alternative.

For upstream transformer, lets suppose target column name is Colour.
create a 2nd column ColourNil immediately before or after this column.
make both target columns NULLABLE.

In the derivation for Colour code If IsNull(inputcolumn) then SetNull() Else inputcolumn.

In the derivation for ColourNil If IsNull(inputcolumn) then "true" else SetNull()

set the xpath expression for the original column (Colour) to the original xpath expression -- for when there IS data "....../Colour/text()"

set the xpath expression for the new column (colourNil) to "......./Colour/@xsi:nil"

Only ONE occurrence of the tag "Colour" will appear in the output message as only one of them is not null at a time.

For hard coded nil columns, of course only the ColourNil Output column would be needed and the transformer derivation would be set to "true".
rcanaran
Premium Member
Premium Member
Posts: 64
Joined: Wed Jun 14, 2006 3:51 pm
Location: CANADA

Post by rcanaran »

I guess the next part would be to try coding a conditional xpath expression. Then I wouldn't need to add the extra output row.
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

you might explore pure xslt and include it in the Stage.
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
rcanaran
Premium Member
Premium Member
Posts: 64
Joined: Wed Jun 14, 2006 3:51 pm
Location: CANADA

Post by rcanaran »

1. No chance yet to explore pure xslt, but that sounds interesting.

2. Datastage is smart enough that when I'm populating an element AND its attributes, it doesn't create 2 sets of tags. I'm sure everyone else knew that, but I didn't :oops:

3. So I can put the 2 rows in the input columns for the xml output stage and set the Nil element(attribute) value to "false" or SetNull() when the element itself is NOT NULL, depending on whether I want xsi:nil="false" to show up or not.

I don't know that I would consider this a SOLUTION yet as i think DS should be able to determine that from the schema or have "nillable" column to check in the element definition somewhere. But its good enough a workaround for me and I don't have to hand-code xml tags, risking a mistranslation of special characters like ampersand (&).
Post Reply