Page 1 of 1

How to write XML tags which occur more than 1 time

Posted: Mon Dec 29, 2003 1:03 am
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

Posted: Mon Dec 29, 2003 8:27 am
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.

Posted: Mon Dec 29, 2003 8:34 am
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.

Posted: Sun Jan 04, 2004 11:40 pm
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.

xml writer output

Posted: Tue Mar 02, 2004 12:35 pm
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.