Package org.jdom2

Examples of org.jdom2.Document


    // Manually construct illegal XML and make sure the outputter notices
    @Test
    public void test_ErrorSurrogatePairOutput() throws JDOMException, IOException, XMLStreamException {
      SAXBuilder builder = new SAXBuilder();
      builder.setExpandEntities(true);
      Document doc = builder.build(new StringReader("<?xml version=\"1.0\"?><root></root>"));
      Text t = new UncheckedJDOMFactory().text("\uD800\uDBFF");
      doc.getRootElement().setContent(t);
      Format format = Format.getCompactFormat().setEncoding("ISO-8859-1");
      StAXStreamOutputter outputter = new StAXStreamOutputter(format);
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      XMLStreamWriter xsw = soutfactory.createXMLStreamWriter(baos);
      try {
View Full Code Here


         
          char[] chars = expect.toCharArray();
          CharArrayReader car = new CharArrayReader(chars);
          XMLStreamReader xsr = sinfactory.createXMLStreamReader(car);
         
      Document backagain = sbuilder.build(xsr);
      xsr.close();
     
      // get a String representation of the round-trip.
        if (backagain.hasRootElement()) {
          normalizeAttributes(backagain.getRootElement());
        }
        StringWriter swb = new StringWriter();
        xsw = soutfactory.createXMLStreamWriter(swb);
      xout.output(backagain, xsw);
      String actual = swb.toString();
View Full Code Here

    }
    }
   
  @Test
  public void testRTOutputDocumentSimple() {
    Document doc = new Document(new Element("root"));
    roundTripDocument(doc);
  }
View Full Code Here

    @Test
  @Ignore
  // TODO
    public void testRTOutputDocumentFull() {
      Document doc = new Document();
      DocType dt = new DocType("root");
      dt.setInternalSubset(" ");
      doc.addContent(dt);
      doc.addContent(new Comment("This is a document"));
      doc.addContent(new ProcessingInstruction("jdomtest", ""));
      Element e = new Element("root");
      e.addContent(new EntityRef("ref"));
      doc.addContent(e);
      roundTripDocument(doc);
    }
View Full Code Here

      roundTripDocument(doc);
    }
   
    @Test
    public void testOutputDocumentRootAttNS() {
      Document doc = new Document();
      Element e = new Element("root");
      e.setAttribute(new Attribute("att", "val", Namespace.getNamespace("ans", "mynamespace")));
      doc.addContent(e);
      roundTripDocument(doc);
    }
View Full Code Here

   
    @Test
    public void testOutputDocumentAttributes() {
      Element emt = new Element("root");
      emt.setAttribute("att", "val");
    Document doc = new Document(emt);
    roundTripDocument(doc);
    }
View Full Code Here

    Namespace ans = Namespace.getNamespace("ans", "attributens");
    emt.addNamespaceDeclaration(ans);
    emt.addNamespaceDeclaration(Namespace.getNamespace("two", "two"));
    emt.setAttribute(new Attribute("att", "val", ans));
    emt.addContent(new Element("child", Namespace.getNamespace("", "childuri")));
    Document doc = new Document(emt);
    roundTripDocument(doc);
    }
View Full Code Here

        throw new SAXException("SHould not be reaching this, ever");
      }
    };
    SAXOutputter saxout = new SAXOutputter(handler, handler, handler, handler, handler);
   
    Document doc = null;
    Element emt = null;
    List<Content> list = null;
    List<Content> empty = new ArrayList<Content>();
    saxout.output(doc);
    saxout.output(emt);
View Full Code Here

            break;
        }
      } else if (ap instanceof Attribute) {
        compare ((Attribute)ap, (Attribute)bp);
      } else if (ap instanceof Document) {
        Document a = (Document)ap;
        Document b = (Document)bp;
        assertEquals(a.getBaseURI(), b.getBaseURI());
        final int sz = a.getContentSize();
        assertTrue(sz == b.getContentSize());
        for (int i = 0; i < sz; i++) {
          compare(a.getContent(i), b.getContent(i));
        }
      }
    }
View Full Code Here

            File f = FileManager.getAppFile(path);
            props.clear();
            if (!f.exists())
                return;
            SAXBuilder b = new SAXBuilder();
            Document d = b.build(f);

            Element root = d.getRootElement();

            // Get config
            props = loadConfig(root);
        } catch (Exception e) {
            throw new RuntimeException("Error loading config", e);
View Full Code Here

TOP

Related Classes of org.jdom2.Document

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.