AW: [jdom-interest] JDOM and Recursive elements
Falk Fraikin
fraikin at informatik.tu-darmstadt.de
Thu Nov 22 05:14:33 PST 2001
Hi,
maybe I got you all wrong, but then again... is it something like this you
are looking for?
>>>
import org.jdom.*;
import org.jdom.output.XMLOutputter;
public class Recursive
{
public static void main(String[] args) throws Exception
{
String[] names = new String[]{"a", "c", "e",};
String[] values = new String[]{"b", "d", "f",};
int size = names.length;
if (size > 0) {
Element rootElem = new Element("NameValuePair");
rootElem.setAttribute("name", names[0]);
rootElem.addContent(new Element("Value").setText(values[0]));
Element currentElem = rootElem;
for (int i = 1; i < size; i++) {
Element newElem = new Element("NameValuePair");
newElem.setAttribute("name", names[i]);
newElem.addContent(new Element("Value").setText(values[i]));
currentElem.addContent(newElem);
currentElem = newElem;
}
XMLOutputter xmlOutputter = new XMLOutputter(" ", true);
xmlOutputter.output(rootElem, System.out);
}
}
}
<<<
Rgds,
Falk
-----Ursprüngliche Nachricht-----
Von: jdom-interest-admin at jdom.org [mailto:jdom-interest-admin at jdom.org]Im
Auftrag von Vijay Gummadi
Gesendet: Mittwoch, 21. November 2001 04:36
An: jdom-interest at jdom.org
Betreff: [jdom-interest] JDOM and Recursive elements
Folks,
After making several attempts and looking up all the archives, I seek
your input in solving this problem I encountered.
How do I use JDOM to write/create an XML document that has a structure
similar to the one shown here:
<NameValuePair name="a">
<Value>b</Value>
<NameValuePair name="c">
<Value>d</Value>
<NameValuePair name="e">
<Value>f</Value>
<!-- NESTING OF ELEMENT NAMEVALUEPAIR CAN GO ON-->
</NameValuePair>
</NameValuePair>
</NameValuePair>
Any help including code samples are highly appreciated.
regards,
Vijay
eMail: vijaykgummadi at hotmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20011122/a5ce959a/attachment.htm
More information about the jdom-interest
mailing list