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();
 }
Example #2
0
  public static void enregistre(Document document, String fichierpath) {
    try {
      // vérifie si document n'est pas nul
      if (document == null) {
        document = new Document();
      }

      // On utilise ici un affichage classique avec getPrettyFormat()
      XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
      // Remarquez qu'il suffit simplement de créer une instance de FileOutputStream
      // avec en argument le nom du fichier pour effectuer la sérialisation.
      sortie.output(document, new FileOutputStream(fichierpath));
      //			new File(fichier).createNewFile();
    } catch (java.io.IOException e) {
    }
  }
Example #3
0
 public static void outputDocument(Document document, Writer out) throws IOException {
   XMLOutputter outputter = new XMLOutputter();
   outputter.setFormat(Format.getPrettyFormat().setEncoding("UTF-8"));
   outputter.output(document, out);
 }
Example #4
0
 public String xmlToString(Document doc) {
   String xml;
   XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
   xml = out.outputString(doc);
   return xml;
 }