XML Output stage

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
adarsh shrinagesh
Premium Member
Premium Member
Posts: 68
Joined: Sat Feb 05, 2005 4:59 am
Location: India

XML Output stage

Post by adarsh shrinagesh »

Hello

While I am able to create a valid xml file sourced from a database table - i am not able to get the xml in the exact format required.

For ex: if the following are source records

Code: Select all

Name	Age
Ad	1
Ak	2
I would like the output xml source code as

<student>
<Name> Ad</Name>
<Age>1</Age>
<Name> Ak</Name>
<Age>2</Age>
</student>

I would like the closing tags of the repeating elements in one single line as opposed to the output format I am currently being able to create using the xml output


<student>
<Name>
Ad
</Name>
<Age>
</Age>
<Name>
Ak
</Name>
<Age>
2
</Age>
</student>

Please advise.



[/code]
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Why? Formatting is for peoples, no process you create this for will care. And you can always "pretty print" it yourself afterwards simply (one way) by opening it in something like IE. That's how the formatted output option in the stage works and looks - "turn it off" is my best advice here.
-craig

"You can never have too many knives" -- Logan Nine Fingers
adarsh shrinagesh
Premium Member
Premium Member
Posts: 68
Joined: Sat Feb 05, 2005 4:59 am
Location: India

Post by adarsh shrinagesh »

chulett wrote:Why? Formatting is for peoples, no process you create this for will care. And you can always "pretty print" it yourself afterwards simply (one way) by opening it in something like IE. That's how the formatted output option in the stage works and looks - "turn it off" is my best advice here.
Hello

Yes, I agree ... I am told however, that there is a downstream application designed to read this data based on the closing tags for a single field ( this is tool migration activity and the earlier product was able to create such a format).

The only other alternative albeit a "dirty" approach -I could think of is to create the tags ourselves in a transformer:
Ex:

Code: Select all


"<":Extract columname:">":ColValue:"</":Extract columname:">"

Defeats the purpose of the XML stage though.

I tried turning the "formatting" off - however the output is freeform text - no line feeds whatsoever.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

That's not "free form" that's proper "xml form"... one big string. I'd be curious what Ernie thinks when he gets a chance to drop by but any process that requires specific XML formatting to work is a poorly designed one. IMHO, of course.

Yes, you can go all Old Skool and do all the tags yourself. Make sure you also account for anything in the data that would need to made "safe" as well like angle brackets or ampersands. My advice still stands: turn off formatting, generate it without any formatting and then use another process (i.e. not DataStage, some command line utility that DataStage runs after job... there are typically plenty to choose from or you can 'roll yer own' should you so desire) post-creation to "pretty print" it... if that's really what you need.
-craig

"You can never have too many knives" -- Logan Nine Fingers
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

Yeah.....you still see this sort of thing every once in awhile.....usually it's with tools that were written when XML was new --- someone insisted back then on having xml in the "model", but formal xml api's weren't used in the code, or the skills weren't there, etc.

....if the xml node is small, then I'd just do it in the Transformer and build it however I need it......if the xml is many more columns, consider building it as an unformatted document (less space) and then pass it right back into xml output and parse it however you need......

....for example, wrap your name and age with another element, such as "person"..... .../person/name/text() and .../person/age/text() ....and then, in a followup downstream xmlInput Stage, just have a single column called Person (varchar, length of say, 20), and use this: .../person/ (don't put in the text() ).........

...now you will have columns whose value is the full tag of name and age <name>fred</name><age>24</age> and can do whatever you want with it.....send it to a sequential file, etc.

Might take further massaging after that, but you get the idea....

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
frolen
Participant
Posts: 7
Joined: Sat Feb 22, 2020 12:03 pm

Post by frolen »

Why?
Post Reply