Covert database table result into XML - How to generate an XML document

derbegefrac

New Member
I have a query that when run returns a resultset with the following data in the order and grouping shown: \[code\]Country Region Town---------------------------------------England North NewCastleEngland North ManchesterEngland North LeedsEngland South LondonEngland South BristolEngland South BirminghamEngland South PortsmouthNorway North TrondheimNorway North TromsoNorway South OsloNorway South StavangerNorway West Bergen\[/code\]Using Java, i would like to convert the returned result into an XML document as shown below:\[code\]<countries> <country> <countryName>England</countryName> <region name = "south"> <town>London</town> <town>Bristol</town> <town>Birmingham</town> <town>Portsmouth</town> </region> <region name = "north"> <town>NewCastle</town> <town>Leeds</town> </region> <country> <country> <countryName>Norway</countryName> <region name = "south"> <town>Oslo</town> <town>Stavanger</town> </region> <region name = "west"> <town>Bergen</town> </region> <region name = "North"> <town>Trondheim</town> <town>Tromso</town> </region> <country><countries>\[/code\]What is the best way to traverse the data so that the tags are created and closed at the correct position? I have seen an example here http://www.mkyong.com/java/how-to-create-xml-file-in-java-jdom-parser/ but the structure of the data is flat unlike the sample i am using which will probably require multiple loops.
 
Back
Top