Result Set to XML. How to generate a tree structure? Please help

Hello everyone,

I went through some of the posts here and I wasnt able to find my answer. Hence I am posting a new thread. If this question was already answered kindly point me to that thread.

My scenario:

I have a result set which has following set up

REGION | STATE | DISTRICT | CUSTOMER

NE| NY|NOT| A

NE| NY|NOT| B

NE| NY|MAN| A

NE| NY|MAN| B

..and so on. I would like to convert that result set into an XML with the following format.

<REGION> NE

<STATE>NY

<DISTRICT>NOT

<CUSTOMER> A </CUSTOMER>

<CUSTOMER> B </CUSTOMER>

</DISTRICT>

<DISTRICT>MAN

<CUSTOMER> A </CUSTOMER>

<CUSTOMER> B </CUSTOMER>

</DISTRICT>

</STATE>

</REGION>

Kindly let me know the possible ways of doing this. Code snippets will be very helpful to me. Thanks in advance

[977 byte] By [crazy_bunnya] at [2007-11-27 8:31:16]
# 1

I know that the site below does not cover exactly what you want but you can customize the code snippets to your needs. All you have to do is to devise a suitable algorithm to avoid the repetition of sibling elements having the same text. With regard to this requirement I advise you to order the records in the ResultSet before processing them because it makes the comparison of the records (which is unavoidable to find the repetitive values) much easier.

http://www.developer.com/db/article.php/3329001

prgguya at 2007-7-12 20:26:41 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...