Package org.jdom2

Examples of org.jdom2.Element


  }

  @Test
  public void testOutputDocumentOmitEncoding() {
    Document doc = new Document();
    doc.addContent(new Element("root"));
    String xmldec = "<?xml version=\"1.0\"?>";
    FormatSetup setup = new FormatSetup() {
      @Override
      public void setup(Format fmt) {
        fmt.setOmitEncoding(true);
View Full Code Here


  }

  @Test
  public void testOutputDocumentOmitDeclaration() {
    Document doc = new Document();
    doc.addContent(new Element("root"));
    FormatSetup setup = new FormatSetup() {
      @Override
      public void setup(Format fmt) {
        fmt.setOmitDeclaration(true);
      }
View Full Code Here

  @Test
  public void testOutputDocumentFull() {
    DocType dt = new DocType("root");
    Comment comment = new Comment("comment");
    ProcessingInstruction pi = new ProcessingInstruction("jdomtest", "");
    Element root = new Element("root");
    Document doc = new Document();
    doc.addContent(dt);
    doc.addContent(comment);
    doc.addContent(pi);
    doc.addContent(root);
View Full Code Here

 
  @Test
  public void testDeepNesting() {
    // need to get beyond 16 levels of XML.
    DocType dt = new DocType("root");
    Element root = new Element("root");
    Document doc = new Document();
    doc.addContent(dt);
    doc.addContent(root);
    String xmldec = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    String dtdec = "<!DOCTYPE root>";
    String lf = "\n";
   
    StringBuilder raw = new StringBuilder();
    raw.append(xmldec).append(lf).append(dtdec);
    StringBuilder pretty = new StringBuilder();
    pretty.append(xmldec).append(lf).append(dtdec);
    if (!usesrawxmlout) {
      // most test systems use the XMLOutputter in raw mode to output
      // the results of the conversion. In Raw mode the XMLOutputter will
      // not make pretty content outside of the root element (but it will
      // put the XMLDeclaration on it's own line).
      // so, in the cases where the actual pretty format is used, we add
      // this newline after the DocType...
      pretty.append(lf);
    }
    raw.append("<root>");
    pretty.append("<root>");
    pretty.append(lf);
    final int depth = 40;
    int cnt = depth;
    Parent parent = root;
    StringBuilder indent = new StringBuilder();
    while (--cnt > 0) {
      Element emt = new Element("emt");
      parent.getContent().add(emt);
      parent = emt;
      raw.append("<emt>");
      indent.append("  ");
      pretty.append(indent.toString());
      pretty.append("<emt>");
      pretty.append(lf);
    }
   
    parent.getContent().add(new Element("bottom"));
    raw.append("<bottom />");
    pretty.append(indent.toString());
    pretty.append("  <bottom />");
    pretty.append(lf);
   
View Full Code Here

    checkOutput(doc, raw.toString(), raw.toString(), pretty.toString(), pretty.toString(), pretty.toString());
  }
 
  @Test
  public void testOutputElementContent() {
    Element root = new Element("root");
    root.addContent(new Element("child"));
    checkOutput(root, "outputElementContent", Element.class, null, "<child />", "<child />", "<child />", "<child />", "<child />");
  }
View Full Code Here

  }

  @Test
  public void testOutputList() {
    List<Object> c = new ArrayList<Object>();
    c.add(new Element("root"));
    checkOutput(c, "output", List.class, null, "<root />", "<root />", "<root />", "<root />", "<root />");
  }
View Full Code Here

 
  @Test
  public void testOutputEscapedMixedMultiText() {
    // this test has mixed content (text-type and not text type).
    // and, it has a multi-text-type at the end.
    Element root = new Element("root");
    root.addContent(new Comment("Boo"));
    root.addContent(new Text(" xx "));
    root.addContent(new Text("<emb>"));
    root.addContent(new Text(" xx "));
    FormatSetup fs = new FormatSetup() {
      @Override
      public void setup(Format fmt) {
        fmt.setExpandEmptyElements(true);
      }
View Full Code Here

  @Test
  @Override // because omit still adds declaration....
  public void testOutputDocumentOmitDeclaration() {
    Document doc = new Document();
    doc.addContent(new Element("root"));
    FormatSetup setup = new FormatSetup() {
      @Override
      public void setup(Format fmt) {
        fmt.setOmitDeclaration(true);
      }
View Full Code Here

  @Test
  public void testTrimFullWhite() throws XMLStreamException {
    // See issue #31.
    // https://github.com/hunterhacker/jdom/issues/31
    // This tests should pass when issue 31 is resolved.
    Element root = new Element("root");
    root.addContent(new Text(" "));
    root.addContent(new Text("x"));
    root.addContent(new Text(" "));
    Format mf = Format.getRawFormat();
    mf.setTextMode(TextMode.TRIM_FULL_WHITE);
    StAXStreamOutputter xout = new StAXStreamOutputter(mf);
    StringWriter sw = new StringWriter();
    XMLStreamWriter xsw = soutfactory.createXMLStreamWriter(sw);
View Full Code Here

          XMLStreamReader xsr = sinfactory.createXMLStreamReader(new StringReader(expect));
          assertTrue(xsr.getEventType() == XMLStreamConstants.START_DOCUMENT);
          assertTrue(xsr.hasNext());
          xsr.next();
         
      Element backagain = (Element)sbuilder.fragment(xsr);

      // convert the input to a SAX Stream

      sw.getBuffer().setLength(0);
          xsw = soutfactory.createXMLStreamWriter(sw);
View Full Code Here

TOP

Related Classes of org.jdom2.Element

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.