Page 1 of 1

Creating Recursively Hierarchical XML files using DataStage

Posted: Sat Aug 25, 2007 7:55 am
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.

Posted: Sat Aug 25, 2007 10:25 am
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?

Posted: Sat Aug 25, 2007 2:50 pm
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.

Posted: Sun Aug 26, 2007 2:55 am
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.

Posted: Sun Aug 26, 2007 2:59 am
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.

Posted: Sun Aug 26, 2007 3:29 am
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

Posted: Sun Aug 26, 2007 5:53 am
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.

Posted: Sun Aug 26, 2007 6:14 am
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.

Posted: Sun Aug 26, 2007 9:56 am
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

Posted: Sun Aug 26, 2007 7:13 pm
by kduke
Follow the link on my signature to my tips page to download the best practices document Ernie was talking about.

recursive XML

Posted: Wed Oct 24, 2007 9:34 am
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?

Re: recursive XML

Posted: Fri Oct 26, 2007 7:49 am
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