XML Stage - Recursive XML parsing

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
visvacfirvin
Premium Member
Premium Member
Posts: 49
Joined: Fri Dec 14, 2007 1:43 pm

XML Stage - Recursive XML parsing

Post by visvacfirvin »

Hi, Is it possible to parse recursive XML using XML assembly stage. Below is an example of recursive XML which i got from internet. There are solutions which are java based. But I've a similar structure which needs to be parsed using Datastage. Please let me know if it is possible and if so how to parse it. Thank you.

Code: Select all

<?xml version="1.0"?>
<CONFIG>
    <FUNCTION>
        <NAME>FUNCT0</NAME>
        <CALLS>
            <FUNCTION>
            <NAME>FUNCT0_0</NAME>
            </FUNCTION>
        </CALLS>
        <CALLS>
            <FUNCTION>
            <NAME>FUNCT0_1</NAME>
            </FUNCTION>
        </CALLS>
    </FUNCTION>
    <FUNCTION>
        <NAME>FUNCT1</NAME>
    </FUNCTION>
</CONFIG>
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

Yes...it can be parsed successfully...but you will need to define "how deep" you want to go in the relationships for each output link that you might want to specify for retrieval of detail.

Simplest is probably to use the xmlInput Stage, and decide "how deep" you want to illustrate --- let's say that you don't expect it to ever get deeper than (say) six levels........

Create a simple xml example like this one that takes you to the six levels of detail --- import that xml document (Import..TableDefinitions...XML Definitions) and open the entire tree in the importer and check the orange attribute icons (if any) at each level, and the lowest inner boxes for elements (the ones with the "T").

Import that into your output link, and also import the namespaces at the namespace tab of that same output link. Make one of the columns at the sixth level of node a "key" (key=yes). Then MAKE CERTAIN that you UNCHECK "Repetition Element Required".

This will retrieve all six levels, and if there aren't six levels for a particular higher level (or not a fifth for a fourth, and not a fourth for a third, etc.), you will get nulls for those lower levels.

On the input side of the Stage you will need to supply the xml as "content" (if it is coming from a database or a message queue, for example), or send in the FileName of the xml by using the External Source Stage in an EE Job [use a unix list command to send in a list of xml docs in a subdirectory] or the Folder Stage in a Server Job. How large are the xml documents? If they are not large, a Server Job will probably work great, as it is very flexible with this kind of string data.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
visvacfirvin
Premium Member
Premium Member
Posts: 49
Joined: Fri Dec 14, 2007 1:43 pm

Post by visvacfirvin »

Thanks Ernie. I'll try the method you mentioned. I was looking to see if XML assembly stage itself can support recursive xml.

Thank you.
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

It can also, same way....you have to declare and then navigate a predetermined depth. The xmlInput Stage is simpler, however, because of its default support for nulls with nodes that dont reach your predefined recursion level. xmlInput Stage can do this nicely via one output link......

Let us know how it goes.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
Post Reply