Creating Recursively Hierarchical XML files using DataStage
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 4
- Joined: Tue Aug 21, 2007 1:52 am
- Location: Chennai
Creating Recursively Hierarchical XML files using DataStage
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.
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Participant
- Posts: 4
- Joined: Tue Aug 21, 2007 1:52 am
- Location: Chennai
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.
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
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
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
Ernie
-
- Participant
- Posts: 4
- Joined: Tue Aug 21, 2007 1:52 am
- Location: Chennai
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.
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
-
- Participant
- Posts: 4
- Joined: Tue Aug 21, 2007 1:52 am
- Location: Chennai
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.
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
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
Thanks.
Ernie
-
- Participant
- Posts: 15
- Joined: Mon Mar 20, 2006 2:03 pm
recursive XML
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?
<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?
-
- Participant
- Posts: 15
- Joined: Mon Mar 20, 2006 2:03 pm
Re: recursive XML
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
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?