Page 1 of 1

XML Output format help

Posted: Thu Apr 29, 2010 3:12 pm
by reachsam11
The XML output when opened in a notepad has new line charactes in between the open and close tags as below.

<?xml version="1.0" encoding="UTF-8"?>
<customers xmlns="http://www.cust.org/Customers" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<customer id="0">
<name>
Porsche
</name>
<order number="1">
<product_code>
1
</product_code>
<quantity>
10
</quantity>
<unit_price>
10000
</unit_price>
</order>
</customer>
</customers>


I like the output to be as below - data in the same line as open and close tags.
<?xml version="1.0" encoding="UTF-8"?>
<customers xmlns="http://www.cust.org/Customers" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<customer id="0">
<name> Porsche</name>
<order number="1">
<product_code>1</product_code>
<quantity>10</quantity>
<unit_price>1000</unit_price>
</order>
</customer>
</customers>

Posted: Thu Apr 29, 2010 3:40 pm
by anbu

Code: Select all

sed -e "/<name>/{N;N;/<\/name>/s/\n//g;}" -e "/<product_code>/{N;N;/<\/product_code>/s/\n//g;}" -e "/<quantity>/{N;N;/<\/quantity>/s/\n//g;}" -e "/<unit_price>/{N;N;/<\/unit_price>/s/\n//g;}" file

Posted: Thu Apr 29, 2010 3:42 pm
by reachsam11
Is it possible to acheive it with in Datastage XML output stage?
anbu wrote:

Code: Select all

sed -e "/<name>/{N;N;/<\/name>/s/\n//g;}" -e "/<product_code>/{N;N;/<\/product_code>/s/\n//g;}" -e "/<quantity>/{N;N;/<\/quantity>/s/\n//g;}" -e "/<unit_price>/{N;N;/<\/unit_price>/s/\n//g;}" file

Posted: Fri Apr 30, 2010 6:26 am
by chulett
No. You've seen what DataStage considers "formatted" output and if that's not what you want you should not enable that option. Keep in mind that formatting like that is only for peoples and no XML reader will care or need any formatting, so most applications don't bother with it.

If somehow you think you really "need" that formatted or "pretty printed" output, that will need to be a separate step done post-generation outside of DataStage using 3rd party utilities.

Posted: Fri Apr 30, 2010 7:21 am
by eostic
...it wastes space. Open the document with a tool that understands XML. Generate formatted output ought to be removed or at least not be the default.

Ernie