import java.io.StringReader;
import org.jdom.Document;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
public class TestXMLOutputter {
public static void main(String args[]) {
try {
testOutput();
} catch (Exception e) {
System.out.println("there was an error" + e.getMessage());
}
}
public static void testOutput() throws Exception {
String desired = "\n\t\n\t\tWebCT\n\t\t Migration\n\t\t2002-06-06T14:59:05\n\t\n";
String b9Trim = "\n\t\n\t\tWebCT\n\t\tMigration\n\t\t2002-06-06T14:59:05\n\t\n";
String b9NoTrim = "\n\t\n\n\t\n\t\t\n \n\t\tWebCT\n\t\t\n \n\t\t Migration\n\t\t\n \n\t\t2002-06-06T14:59:05\n\t\t\n\n\t\n\t\n\n";
String xml =
"\n"+
"\n"+
" WebCT\n"+
" Migration\n"+
" 2002-06-06T14:59:05\n"+
"\n"+
"\n";
SAXBuilder builder = new SAXBuilder();
builder.setIgnoringElementContentWhitespace(true);
Document doc = builder.build(new StringReader(xml));
XMLOutputter xmlOutputter = new XMLOutputter("\t", true);
xmlOutputter.setOmitDeclaration(true);
xmlOutputter.setLineSeparator("\n");
xmlOutputter.setTextTrim(true);
String output = xmlOutputter.outputString(doc.getRootElement());
if (desired.equals(output)) {
System.out.println("yay!");
} else if (b9Trim.equals(output)) {
System.out.println("boo! \" Migration\" is missing spaces");
} else if (b9NoTrim.equals(output)) {
System.out.println("boo! a whole bunch of extra tabs and spaces");
} else {
System.out.println("Something else happened");
System.out.println(output);
}
}
}