How to write XML tags which occur more than 1 time

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
sansan
Premium Member
Premium Member
Posts: 19
Joined: Fri Jun 20, 2003 4:24 am

How to write XML tags which occur more than 1 time

Post by sansan »

Hi,
I want to produce an XML file,but I faced one problem.I have tags which occurs 4 times (TotalPayments).
I don't how to write it in Xpath to occur 4 times in the output XML file.I tried to use (SaleRecord//TotalPayment/Subtotal)
but show me the error "the derivation rule is invalid". Currently, I'm using XML 2 pack.


Output Records look like this:
<SaleRecord>
<Din>123456</Din>
<SerialNo>1</SerialNo>
<TotalPayment>
<Subtotal>124</Subtotal>
<Balance>1234</Balance>
</TotalPayment>
<TotalPayment>
<Subtotal>156</Subtotal>
<Balance>1978</Balance>
</TotalPayment>
<TotalPayment>
<Subtotal>678</Subtotal>
<Balance>9999</Balance>
</TotalPayment>
<TotalPayment>
<Subtotal>563</Subtotal>
<Balance>4444</Balance>
</TotalPayment>
</SaleRecord>


Thanks a lot,
san san
cmueller
Participant
Posts: 46
Joined: Wed Oct 23, 2002 7:10 am

Post by cmueller »

Pipe any non repeating data to a hashed file stage, using serialno for the key. Then pipe repeating tags to the an xmloutput stage, and then to another hashed file stage to which you will write the repeating tags as xml chunks and use the serialno as key. It may look like this
SerialNo:1
TotalPayment: <Subtotal>124</Subtotal><Balance>1234</Balance> <Subtotal>156</Subtotal><Balance>1978</Balance> <Subtotal>678</Subtotal><Balance>9999</Balance> <Subtotal>563</Subtotal><Balance>4444</Balance>

Then you can join both hashed files using the second as a lookup and pipe it all to an xmloutput stage.
trobinson
Participant
Posts: 208
Joined: Thu Apr 11, 2002 6:02 am
Location: Saint Louis
Contact:

Post by trobinson »

I'm not sure what you are asking. Asusming you want Subtotals repeated 4 times within a TotalPayment within a Sale Record then;

Try /SaleRecord/TotalPayment/SubTotal/text() in the description of the XPATH and mark the column as the key column. Defining a column as key defines the column as a repeating group.
sansan
Premium Member
Premium Member
Posts: 19
Joined: Fri Jun 20, 2003 4:24 am

Post by sansan »

Thanks you very much,cmueller.
I'm able to write the repeating tags to the xmloutput,but is there any other ways instead of using hash files? As I have over 10 millions records which saved in the hash files,and then it's comsuming a lot of spaces in DatastagServer.
netboyks
Participant
Posts: 20
Joined: Sat Mar 08, 2003 7:43 am

xml writer output

Post by netboyks »

cmuller,
In your solution could you let me know how to handle a situation where I need the following output format. Please look at the last record. In summary I need to produce a closing tag (</Balance>) if there is no Balance value for the SubTotal.

TotalPayment: <Subtotal>124</Subtotal><Balance>1234</Balance> <Subtotal>156</Subtotal><Balance>1978</Balance> <Subtotal>678</Subtotal></Balance>

Thanks

Netboyks.
cmueller wrote:Pipe any non repeating data to a hashed file stage, using serialno for the key. Then pipe repeating tags to the an xmloutput stage, and then to another hashed file stage to which you will write the repeating tags as xml chunks and use the serialno as key. It may look like this
SerialNo:1
TotalPayment: <Subtotal>124</Subtotal><Balance>1234</Balance> <Subtotal>156</Subtotal><Balance>1978</Balance> <Subtotal>678</Subtotal><Balance>9999</Balance> <Subtotal>563</Subtotal><Balance>4444</Balance>

Then you can join both hashed files using the second as a lookup and pipe it all to an xmloutput stage.
Post Reply