public String createTable() {
   Element root = new Element("table");
   root.setAttribute("border", "0");
   Document doc = new Document(root);
   Element thead = new Element("thead");
   Element th = new Element("th");
   th.addContent("A header");
   th.setAttribute("class", "aka_header_border");
   thead.addContent(th);
   Element th2 = new Element("th");
   th2.addContent("Another header");
   th2.setAttribute("class", "aka_header_border");
   thead.addContent(th2);
   root.addContent(thead);
   Element tr1 = new Element("tr");
   Element td1 = new Element("td");
   td1.setAttribute("valign", "top");
   td1.setAttribute("class", "cellBorders");
   td1.setText("cell contents");
   tr1.addContent(td1);
   root.addContent(tr1);
   XMLOutputter outp = new XMLOutputter();
   Format format = Format.getPrettyFormat();
   format.setOmitDeclaration(true);
   outp.setFormat(format);
   Writer writer = new StringWriter();
   try {
     outp.output(doc, writer);
   } catch (IOException e) {
     e
         .printStackTrace(); // To change body of catch statement use File | Settings | File
                             // Templates.
   }
   return writer.toString();
 }
示例#2
0
 public String getAsXML() {
   // following lines uses the old JDOM jar
   //        xmlOutputter.setIndent(true);
   //        xmlOutputter.setIndent("  ");
   //        xmlOutputter.setNewlines(true);
   //        xmlOutputter.setExpandEmptyElements(false);
   //        xmlOutputter.setOmitEncoding(true);
   //        xmlOutputter.setOmitDeclaration(true);
   //        xmlOutputter.setTextNormalize(true);
   final Format prettyFormat = Format.getPrettyFormat();
   prettyFormat.setExpandEmptyElements(false);
   prettyFormat.setOmitEncoding(true);
   prettyFormat.setOmitDeclaration(true);
   prettyFormat.setTextMode(Format.TextMode.NORMALIZE);
   final XMLOutputter xmlOutputter = new XMLOutputter(prettyFormat);
   return xmlOutputter.outputString(createRootTree("class name list template"));
 }