예제 #1
0
  public String formatAsXHTML(String xhtml) throws IOException, JDOMException {
    DocType doctype =
        new DocType(
            "html", "-//W3C//DTD XHTML 1.1//EN", "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd");
    Namespace namespace = Namespace.getNamespace("http://www.w3.org/1999/xhtml");

    org.jdom2.Document document = XHTMLUtils.parseXHTMLDocument(xhtml);

    org.jdom2.Element root = document.getRootElement();
    root.setNamespace(namespace);
    root.addNamespaceDeclaration(namespace);
    IteratorIterable<org.jdom2.Element> elements = root.getDescendants(Filters.element());
    for (org.jdom2.Element element : elements) {
      if (element.getNamespace() == null) {
        element.setNamespace(Constants.NAMESPACE_XHTML);
      }
    }
    document.setDocType(doctype);

    XMLOutputter outputter = new XMLOutputter();
    Format xmlFormat = Format.getPrettyFormat();
    outputter.setFormat(xmlFormat);
    outputter.setXMLOutputProcessor(new XHTMLOutputProcessor());
    String result = outputter.outputString(document);
    return result;
  }
 public Api1XmlConverter() {
   xmlOutputter = new XMLOutputter();
   doc = new Document();
   doc.setDocType(new DocType("xml"));
   doc.setProperty("version", "1.0");
   doc.setProperty("encoding", "UTF-8");
 }
예제 #3
0
  // provide a test document in the above static variables
  void setupDoc() {
    // create a JDOM tree with just some elements
    root = new Element("decoderIndex-config");
    doc = new Document(root);
    doc.setDocType(new DocType("decoderIndex-config", "decoderIndex-config.dtd"));

    // add some elements
    root.addContent(
        decoderIndexElement =
            new Element("decoderIndex")
                .addContent(
                    new Element("mfgList")
                        .addContent(new Element("manufacturer").setAttribute("mfg", "NMRA"))
                        .addContent(
                            new Element("manufacturer")
                                .setAttribute("mfg", "Digitrax")
                                .setAttribute("mfgID", "129")))
                .addContent(
                    new Element("familyList")
                        .addContent(
                            family1 =
                                new Element("family")
                                    .setAttribute("mfg", "NMRA")
                                    .setAttribute("name", "NMRA S&RP definitions")
                                    .setAttribute("file", "NMRA.xml")
                                    .addContent(
                                        new Element("model")
                                            .setAttribute("model", "full set")
                                            .setAttribute("comment", "all CVs in RP 9.2.1"))
                                    .addContent(
                                        new Element("model")
                                            .setAttribute("model", "required set")
                                            .setAttribute("comment", "required CVs in RP 9.2.1")))
                        .addContent(
                            family2 =
                                new Element("family")
                                    .setAttribute("mfg", "Digitrax")
                                    .setAttribute("name", "FX2 family")
                                    .setAttribute("file", "DH142.xml")
                                    .addContent(
                                        new Element("model")
                                            .setAttribute("model", "DH142")
                                            .setAttribute("numFns", "4")
                                            .setAttribute("numOuts", "2")
                                            .setAttribute("lowVersionID", "21"))
                                    .addContent(
                                        new Element("model")
                                            .setAttribute("model", "DN142")
                                            .setAttribute("numFns", "5")
                                            .setAttribute("numOuts", "1")
                                            .addContent(
                                                new Element("versionCV")
                                                    .setAttribute("lowVersionID", "22")
                                                    .setAttribute(
                                                        "highVersionID",
                                                        "24")))))); // end of adding contents

    return;
  }
예제 #4
0
  public static void validateJDOM(Document pdocument) {
    try {

      //			XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
      DocType type = new DocType("evenement", "evenement.dtd");
      pdocument.setDocType(type);
      XMLOutputter outputter = new XMLOutputter();

      outputter.output(pdocument, System.out);

    } catch (IOException e) {
      System.out.println("format xml non respecté _ 2");
      //			e.printStackTrace();

    }
  }
예제 #5
0
 @Test
 public void testDocumentDocType() {
   Document content = new Document();
   content.setDocType(new DocType("root"));
   assertEquals(
       "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE root>\n",
       outputString(fraw, content));
   assertEquals(
       "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE root>\n",
       outputString(fcompact, content));
   assertEquals(
       "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE root>\n",
       outputString(fpretty, content));
   assertEquals(
       "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE root>\n",
       outputString(ftso, content));
   assertEquals(
       "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE root>\n",
       outputString(ftfw, content));
 }