Creating Recursively Hierarchical XML files using DataStage

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
Dibya Prasad Mishra
Participant
Posts: 4
Joined: Tue Aug 21, 2007 1:52 am
Location: Chennai

Creating Recursively Hierarchical XML files using DataStage

Post by Dibya Prasad Mishra »

Is it possible to develop a variable length recursively hierarchical XML file using DataStage? For example the hirarchy of manager and employee, or that of organisation structure.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Welcome! :D

I don't see why not, but you'd need to be more specific in your needs or questions. Examples are always good. Are you familiar at all with creating XML with DataStage?
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

DataStage server edition is singularly well-equipped for this task, since data are processed within DataStage as character strings, exactly as they are in XML, and variable-length is a given. The actual approach taken would depend on how many levels of hierarchy are needed. Even so, an arbitrary number of levels ought to be able to be supported.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Dibya Prasad Mishra
Participant
Posts: 4
Joined: Tue Aug 21, 2007 1:52 am
Location: Chennai

Post by Dibya Prasad Mishra »

Thanks Craig for your warm Response.

Well, precisely the need is like this: We are to develop an XML file depicting the organisation tree structure. For this we have an XSD that has one element "Orgnsnstructure"of type "Organisation hierarchy" which comprises some relevant elements including the element "Child orgsn" that comes last in the sequence, and having type that of "Organisation hierarchy". That means here it recursively defines the child organisation under the main one.
To generallise, it would better to say how to implement a tree structure of variable length(there should not be a maximum depth restriction) XML using DataStage.
Dibya
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

I would be inclined to solve this using a hashed file together with a little known command called WITHIN, designed specifically for this kind of nested, or recursive, traversal.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

LIke any complex XML tree to be created in DS, you need to build each individually nested node (XMLOutput does this naturally) and then put those nodes back together....it requires multiple calls to the XMLOutput Stage. There have been lots of threads on xml that reference the best practices document at kduke's site. You will need this document for the best pointers on how this is done.

Ernie
Dibya Prasad Mishra
Participant
Posts: 4
Joined: Tue Aug 21, 2007 1:52 am
Location: Chennai

Post by Dibya Prasad Mishra »

Hi ray,
Thanks for being so forthcoming. Yes it looks plausible to go for use of "WITHIN" in the Hash lookup to grab all the children of a particular node and recursively generate the path from it till the leaf is reached. But, the whole problem lies in the fact that except for the root which is described by "parent Deptorghierarchy", all else are described by "Child orghierarchy", and this metadata defns is going to be static at XML output Stage and it can't be changed for the nodes that come under the first level of the tree and onwards.
Please see if I'm correct.
Dibya
Dibya Prasad Mishra
Participant
Posts: 4
Joined: Tue Aug 21, 2007 1:52 am
Location: Chennai

Post by Dibya Prasad Mishra »

Hi Ernie,

Thanks for spending some thought on this. I've tried a few approaches that create nested nodes separately and reunite them based on the impression that XML output satge will do it naturally, but everytime it has proven wrong. Yes, I've not tried the way you have suggested to take a feedback of the XML O/P stage . Let me do it like that and see.
Dibya
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

Can you describe a bit more what you mean by your recursive XML document? Perhaps with an example? I've seen many xml schema that use polymorphism to describe different kinds of "like" meta data, but ultimately have only seen nested nodes in actual document instances that have a fixed number of sub-elements (fixed depth), even if the elements at each "level" have the same names. Seeing it will also help us visualize some techniques for the best solution.

Thanks.

Ernie
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

Follow the link on my signature to my tips page to download the best practices document Ernie was talking about.
Mamu Kim
wenfei.chen
Participant
Posts: 15
Joined: Mon Mar 20, 2006 2:03 pm

recursive XML

Post by wenfei.chen »

Now I have similar problem. I want to read the recursive XML into different tables. For example:

<EmployeeNo 100>
Name='a'
<EmployeeNo 102>
Name = 'b'
</EmployeeNo>
<EmployeeNo 201>
Name = 'c'
</EmployeeNo>
<EmployeeNo 103>
Name = 'z'
</EmployeeNo>
</EmployeeNo>

which means c reports to b. b and z report to a. And the recursive level is variable. Does anyone have any idea how to deal with this it? I am thinking about to convert the structure to

<EmployeeNo=100, reportTo="">Name='a'</EmployeeNo>
<EmployeeNo=102, reportTo="100">Name='a'</EmployeeNo>
...

but how to do that?
What's the next?
wenfei.chen
Participant
Posts: 15
Joined: Mon Mar 20, 2006 2:03 pm

Re: recursive XML

Post by wenfei.chen »

I already figured it out by using or XSLT or XPath. If use XPATH, use ../@employeeno for parent, //EMPLOYEE/@employeeno for the current node.

for XSLT:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:apply-templates select="//EMPLOYEE"/>
</xsl:template>

<xsl:template match="EMPLOYEE">
[<xsl:value-of select="@employeeno "/>]-[<xsl:value-of select="../@employeeno " />]
</xsl:template>
</xsl:stylesheet>

Hope this can help
What's the next?
Post Reply