Page 1 of 1

XML Input and Primary Keys

Posted: Wed Mar 03, 2010 5:09 pm
by sbukhari1
I am using a complex XML structure that has many levels. Within one level (3 levels deep) I am selecting a number of attributes to create an output file that is flat for that segment of the XML.

My job design is simple:

External Data Source -> XML Input -> Sequential File

In the output I am expecting 4 records. When I select the natural key of the segment as Key I get the unique values for the Key attribute, however all other attributes are repeated for the first occurrence of the natural key. When I select another attribute that I expect to be unique across 4 records I get unique value of that attribute but repeating Natural Key for the following 3 records.

What am I doing wrong?

Posted: Wed Mar 03, 2010 6:31 pm
by chulett
Probably nothing. :wink:

FYI - that 'key' field option marks the Repetition Element and is nothing like a Primary Key. Typically one would set it to the lowest level element but sometimes to have to play games. If you truly have many 'levels' then you may need to pull the levels out with one XML Input stage and then use another to parse the levels themselves. I'm a little lost on your explanation so for someone like me, examples would be a Good Idea - snippets of your source and examples of what your output looks like in the various scenarios you outlined here.

Of course, Ernie probably grokked all this straight away, we could always wait for him. I'll sure he'll be along in a minute or two.... [whistles a merry ditty]

Oh, study material - be sure to pull down and cozy up with the XML Best Practices document on Kim Duke's website, all kinds of good information there on working XML with DataStage. 8)

Posted: Wed Mar 03, 2010 7:56 pm
by eostic
Craig...you are too funny.

Indeed, Craig is right, the "key" is nothing more than an indicator for the repeating level that you want to retrieve. There are no keys --- just instances of elements.

Each "independent" repeating node (or deeply nested set of nodes) must be on its own link.

See lots of references as noted above -- I also have some things at my blog noted below.

Ernie