Package fi.luomus.commons.xml

Examples of fi.luomus.commons.xml.XMLWriter


  }

  private void writeXMLToOut(Document doc) throws Exception {
    res.setContentType("application/xml; charset=utf-8");
    PrintWriter out = res.getWriter();
    out.write(new XMLWriter(doc).generateXML(XMLWriter.NO_EMPTY_ELEMENTS));
    out.flush();
  }
View Full Code Here


    out.write(new XMLWriter(doc).generateXML(XMLWriter.NO_EMPTY_ELEMENTS));
    out.flush();
  }

  private void writeJSONToOut(Document doc) throws Exception {
    JSONObject jsonObject = XML.toJSONObject(new XMLWriter(doc).generateXML(XMLWriter.NO_EMPTY_ELEMENTS));
    res.setContentType("application/json; charset=utf-8");
    PrintWriter out = res.getWriter();
    out.write(jsonObject.toString());
    out.flush();
  }
View Full Code Here

    doc.getRootNode().addChildNode("int").setContents("0100");
    doc.getRootNode().addChildNode("int").setContents("00100");
    doc.getRootNode().addChildNode("int").setContents("000100");
    doc.getRootNode().addChildNode("int").setContents("000000");
    doc.getRootNode().addChildNode("int").setContents("1");
    String xml = new XMLWriter(doc).generateXML();

    JSONObject json = XML.toJSONObject(xml);
    String expected = "{\"root\":{\"int\":[\"0100\",\"00100\",\"000100\",\"000000\",\"1\"]}}";
    Assert.assertEquals(expected, json.toString());
  }
View Full Code Here

      Node messageNode = root.getNode("message");
      messageNode.setContents(messageNode.getContents() + " \n " + message);
    } else {
      root.addChildNode("message").setContents(message);
    }
    xml = new XMLWriter(document).generateXML();

    HttpEntity entity = new StringEntity(xml, "application/xml", "UTF-8");
    request.setEntity(entity);

    HttpResponse response = httpclient.execute(request);
View Full Code Here

    public void test_() {
      Document document = new Document("root");
      Node root = document.getRootNode();
      root.addAttribute("attribute", "value with \"quotes\" & 'apostrophes' ");
      root.addAttribute("second", "other <value> ");
      String xml = new XMLWriter(document).generateXML();
      String expected = "" +
      "<?xml version='1.0' encoding='utf-8'?>\n" +
      "<root attribute=\"value with &quot;quotes&quot; &amp; &apos;apostrophes&apos;\" second=\"other &lt;value&gt;\" />";
      assertEquals(expected.trim(), xml.trim());
     
View Full Code Here

      Document document = new Document("root");
      Node root = document.getRootNode();
      root.addChildNode("node").setContents("value's öäÖÄ jes").addAttribute("a1", "v1");
      root.addChildNode("other-node").addChildNode("sub-node").addAttribute("a2", "v2");
      root.addChildNode("data").setCDATA("1234567890 &ent; &amp; & // &quot;    ");
      String xml = new XMLWriter(document).generateXML();
      String expected = "" +
      "<?xml version='1.0' encoding='utf-8'?>\n" +
      "<root>\n" +
      "\n" +
      "  <node a1=\"v1\">value&apos;s öäÖÄ jes</node>\n" +
View Full Code Here

   
    public void test__3() {
      Document document = new Document("root");
      Node root = document.getRootNode();
      root.addChildNode("node").setContents("something with a \n newline");
      String xml = new XMLWriter(document).generateXML();
      String expected = "" +
      "<?xml version='1.0' encoding='utf-8'?>\n" +
      "<root>\n" +
      "\n" +
      "  <node>something with a \n"
View Full Code Here

      assertNotSame(n.getID(), new Node("n").getID());
    }
   
    public void test__writing_document_with_empty_root_with_noemptyelements_set_to_false___should_write_root_element() {
      Document document = new Document("root");
      String xml = new XMLWriter(document).generateXML(XMLWriter.INCLUDE_EMPTY_ELEMENTS);
      String expected = "" +
      "<?xml version='1.0' encoding='utf-8'?>\n" +
      "<root />";
      assertEquals(expected.trim(), xml.trim());
    }
View Full Code Here

      assertEquals(expected.trim(), xml.trim());
    }
   
    public void test__writing_document_with_empty_root_with_noemptyelements_set_to_true___should_write_root_element() {
      Document document = new Document("root");
      String xml = new XMLWriter(document).generateXML(XMLWriter.NO_EMPTY_ELEMENTS);
      String expected = "" +
      "<?xml version='1.0' encoding='utf-8'?>\n" +
      "<root />";
      assertEquals(expected.trim(), xml.trim());
    }
View Full Code Here

    Document document = new Document("root-node");
    Node root = document.getRootNode();
    root.addChildNode("child").addAttribute("attribute", "value");
    root.addChildNode("child").addChildNode("grandchild").setContents("some content here");

    String xml = new XMLWriter(document).generateXML();
    System.out.println();
    System.out.println(xml);
    System.out.println();
  }
View Full Code Here

TOP

Related Classes of fi.luomus.commons.xml.XMLWriter

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.