How to generate xml output of below format

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
ramakrishna459
Participant
Posts: 37
Joined: Tue Mar 26, 2013 12:02 pm
Location: INDIA

How to generate xml output of below format

Post by ramakrishna459 »

Hi all

I have below requirement for generating xml output.

Below are the columns DEPT and its value 01
likewise class and its value 02

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<RECS>
<REC>
<PROPERTY NAME="DEPT">
<VALUE>01</VALUE>
</PROPERTY>
<PROPERTY NAME="Class">
<<VALUE>02</VALUE>
</PROPERTY>
<PROPERTY NAME="SECTION">
<VALUE>ABC</VALUE>
</PROPERTY>
<PROPERTY NAME="SECTIONCODE">
<VALUE>1010</VALUE>
</PROPERTY>
<PROPERTY NAME="COLORcode">
<<VALUE>3435</VALUE>
</PROPERTY>
<PROPERTY NAME="CountOFREG1">
<VALUE>20</VALUE>
</PROPERTY>
<PROPERTY NAME="CountofREG2">
<VALUE>21</VALUE>
</PROPERTY>
</REC>
</RECS>

Could you please share ur suggestions.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Welcome aboard. XML is free-format. DataStage does not generate "pretty" XML - it generates functional XML. There are lots of tools out there for prettifying XML.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ramakrishna459
Participant
Posts: 37
Joined: Tue Mar 26, 2013 12:02 pm
Location: INDIA

Post by ramakrishna459 »

Thanks Ray.But am new to xml.our requirement is to generate the above xml for each record.could you please through some light on the difference between pretty and functional xml.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Being "new to XML" could turn this into a long and painful conversation as it's not really something you could learn in a forum post or twelve. Is there anyone you work with who knows XML and could help? Most of what you'd need to do is not specific to DataStage, so don't let that scare someone off from helping you.

Also, clarify for us your "below format" need. Ray was referring to the layout of what you posted rather than the details of each element and the fact that XML doesn't need to be indented in any fashion and is typically delivered in "one long string". A tool like I.E. can "pretty print" it to make it easier for a person to read but you don't typically generate it like that.

Now... do you have an xsd for the XML file you need to create? If not, can you ask for one? It will go a long way towards getting whatever stage you end up using in the proper format.
-craig

"You can never have too many knives" -- Logan Nine Fingers
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I'd also like to know your exact version of DataStage.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ramakrishna459
Participant
Posts: 37
Joined: Tue Mar 26, 2013 12:02 pm
Location: INDIA

Post by ramakrishna459 »

I was able to generate the above format but am ending up using two xml output stages ...is there anyway to do in single xml stage.

I dont have XSD.

Thanks craig for your valuble response.
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

This is one of those xml documents that has a fairly poor design.....it would have been better if the element names were truly the metadata...in this case, the property "name" is the metadata. We'll assume for the moment that things like DEPT, Class and SECTION are actually columns on your upstream data on a link....

Each "value" element will be easily created when you have a single "row" for each property and value combination. Accomplish that by first pivoting your data....so that if you have 10 columns per row...turn that into 10 rows. ...and then one single XML Stage will be able to create this, with value as your repeating element (the key) and only two columns coming into the stage...... PropertyName and PropertyValue.

The xpath (description property on the input link of the xmlOutput Stage), will be something like...

/recs/rec/property/@NAME
/recs/rec/property/value/text()

Do a lot of searching and reading thru the threads here if you aren't yet familiar with the use of XPATH in the Stage, or of repeating elements, or of how to do a PIVOT.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
ramakrishna459
Participant
Posts: 37
Joined: Tue Mar 26, 2013 12:02 pm
Location: INDIA

Post by ramakrishna459 »

you are true....if the elements name could be the column names and if there is any repitation element it could be easily to acomplish.
Post Reply