<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=Windows-1252">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.0.4712.0">
<TITLE>AW: [jdom-interest] JDOM and Recursive elements</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=2>Hi,</FONT>
</P>
<P><FONT SIZE=2>maybe I got you all wrong, but then again... is it something like this you are looking for?</FONT>
</P>
<P><FONT SIZE=2>>>></FONT>
<BR><FONT SIZE=2>import org.jdom.*;</FONT>
<BR><FONT SIZE=2>import org.jdom.output.XMLOutputter;</FONT>
</P>
<P><FONT SIZE=2>public class Recursive</FONT>
<BR><FONT SIZE=2>{</FONT>
<BR><FONT SIZE=2> public static void main(String[] args) throws Exception</FONT>
<BR><FONT SIZE=2> {</FONT>
<BR><FONT SIZE=2> String[] names = new String[]{"a", "c", "e",};</FONT>
<BR><FONT SIZE=2> String[] values = new String[]{"b", "d", "f",};</FONT>
<BR><FONT SIZE=2> int size = names.length;</FONT>
<BR><FONT SIZE=2> if (size > 0) {</FONT>
<BR><FONT SIZE=2> Element rootElem = new Element("NameValuePair");</FONT>
<BR><FONT SIZE=2> rootElem.setAttribute("name", names[0]);</FONT>
<BR><FONT SIZE=2> rootElem.addContent(new Element("Value").setText(values[0]));</FONT>
<BR><FONT SIZE=2> Element currentElem = rootElem;</FONT>
<BR><FONT SIZE=2> for (int i = 1; i < size; i++) {</FONT>
<BR><FONT SIZE=2> Element newElem = new Element("NameValuePair");</FONT>
<BR><FONT SIZE=2> newElem.setAttribute("name", names[i]);</FONT>
<BR><FONT SIZE=2> newElem.addContent(new Element("Value").setText(values[i]));</FONT>
<BR><FONT SIZE=2> currentElem.addContent(newElem);</FONT>
<BR><FONT SIZE=2> currentElem = newElem;</FONT>
<BR><FONT SIZE=2> }</FONT>
<BR><FONT SIZE=2> XMLOutputter xmlOutputter = new XMLOutputter(" ", true);</FONT>
<BR><FONT SIZE=2> xmlOutputter.output(rootElem, System.out);</FONT>
<BR><FONT SIZE=2> }</FONT>
<BR><FONT SIZE=2> }</FONT>
<BR><FONT SIZE=2>}</FONT>
<BR><FONT SIZE=2><<<</FONT>
</P>
<P><FONT SIZE=2>Rgds,</FONT>
</P>
<P><FONT SIZE=2>Falk</FONT>
</P>
<BR>
<P><FONT SIZE=2>-----Ursprüngliche Nachricht-----</FONT>
<BR><FONT SIZE=2>Von: jdom-interest-admin@jdom.org [<A HREF="mailto:jdom-interest-admin@jdom.org">mailto:jdom-interest-admin@jdom.org</A>]Im Auftrag von Vijay Gummadi</FONT>
<BR><FONT SIZE=2>Gesendet: Mittwoch, 21. November 2001 04:36</FONT>
<BR><FONT SIZE=2>An: jdom-interest@jdom.org</FONT>
<BR><FONT SIZE=2>Betreff: [jdom-interest] JDOM and Recursive elements</FONT>
</P>
<BR>
<P><FONT SIZE=2>Folks,</FONT>
</P>
<P><FONT SIZE=2> After making several attempts and looking up all the archives, I seek your input in solving this problem I encountered.</FONT></P>
<P><FONT SIZE=2> How do I use JDOM to write/create an XML document that has a structure similar to the one shown here:</FONT>
</P>
<P><FONT SIZE=2> <NameValuePair name="a"></FONT>
<BR><FONT SIZE=2> <Value>b</Value></FONT>
<BR><FONT SIZE=2> <NameValuePair name="c"></FONT>
<BR><FONT SIZE=2> <Value>d</Value></FONT>
<BR><FONT SIZE=2> <NameValuePair name="e"></FONT>
<BR><FONT SIZE=2> <Value>f</Value></FONT>
<BR><FONT SIZE=2> <!-- NESTING OF ELEMENT NAMEVALUEPAIR CAN GO ON--></FONT>
<BR><FONT SIZE=2> </NameValuePair></FONT>
<BR><FONT SIZE=2> </NameValuePair></FONT>
<BR><FONT SIZE=2> </NameValuePair></FONT>
</P>
<P><FONT SIZE=2> Any help including code samples are highly appreciated.</FONT>
</P>
<P><FONT SIZE=2>regards,</FONT>
<BR><FONT SIZE=2>Vijay</FONT>
<BR><FONT SIZE=2>eMail: vijaykgummadi@hotmail.com</FONT>
</P>
</BODY>
</HTML>