No subject
Fri Aug 6 17:04:17 PDT 2004
I am expecting output like
<parent>
First String Content
<firstSub>1 content</firstSub>
<secondSub>2 content</secondSub>
<thirdSub>3 content</thirdSub>
</parent>
but instead it is coming out like this
<parent>
First String Content
<secondSub>2 content</secondSub>
<thirdSub>3 content</thirdSub>
<firstSub>1 content</firstSub>
</parent>
Here is sample code
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.*;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
public class MarkTest {
public static void main(String[] args) {
Element parent = new Element("parent");
parent.addContent("First String Content\n");
Element firstSub = new Element("firstSub").addContent("1 content");
parent.addContent(firstSub);
Element secondSub = new Element("secondSub").addContent("2
content");
Element thirdSub = new Element("thirdSub").addContent("3 content");;
LinkedList sublist = new LinkedList();
sublist.add(secondSub);
sublist.add(thirdSub);
List curContent =parent.getMixedContent();
curContent.addAll(sublist);
XMLOutputter xout = new XMLOutputter("\t", true);
try {
System.out.println("What does it look like?
\n"+xout.outputString(parent));
} catch (Exception e){
e.printStackTrace();
}
}
}
More information about the jdom-interest
mailing list