Package fi.luomus.commons.xml.Document

Examples of fi.luomus.commons.xml.Document.Node


      assertEquals("other <value>", root.getAttributes().get(1).getValue());
    }
   
    public void test__2() {
      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" +
      "\n" +
      "  <other-node>\n" +
      "    <sub-node a2=\"v2\" />\n" +
      "  </other-node>\n" +
      "\n" +
      "  <data>\n" +
      "<![CDATA[1234567890 &ent; &amp; & // &quot;    ]]>\n" +
      "  </data>\n" +
      "\n" +
      "</root>";
      assertEquals(expected.trim(), xml.trim());
     
      XMLReader reader = new XMLReader();
      document = reader.parse(xml);
      root = document.getRootNode();
      assertEquals(true, root.hasChildNodes());
      assertEquals(false, root.hasContents());
      assertEquals(3, root.getChildNodes().size());
      assertEquals(false, root.hasAttributes());
      assertEquals(0, root.getAttributes().size());
     
      Node node = root.getChildNodes().get(0);
      assertEquals("node", node.getName());
      assertEquals(1, node.getAttributes().size());
      assertEquals(0, node.getChildNodes().size());
      assertEquals("value's öäÖÄ jes", node.getContents());
     
      Node otherNode = root.getChildNodes().get(1);
      assertEquals("other-node", otherNode.getName());
      assertEquals(false, otherNode.hasAttributes());
      assertEquals(1, otherNode.getChildNodes().size());
      assertEquals("sub-node", otherNode.getChildNodes().get(0).getName());
      assertEquals("v2", otherNode.getChildNodes().get(0).getAttributes().get(0).getValue());
     
      assertEquals("1234567890 &ent; &amp; & // &quot;    ", root.getChildNodes().get(2).getContents());
    }
View Full Code Here


      assertEquals("1234567890 &ent; &amp; & // &quot;    ", root.getChildNodes().get(2).getContents());
    }
   
    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"
      " newline</node>\n" +
      "\n" +
      "</root>";
      assertEquals(expected.trim(), xml.trim());
     
      XMLReader reader = new XMLReader();
      document = reader.parse(xml);
      Node node = document.getRootNode().getNode("node");
     
      expected = "" +
      "something with a \n" +
      " newline";
      assertEquals(expected, node.getContents());
    }
View Full Code Here

      " newline";
      assertEquals(expected, node.getContents());
    }
   
    public void test__nodeID() {
      Node n = new Node("n");
      assertEquals(36, n.getID().length())
      assertEquals(n.getID(), n.getID());
      assertNotSame(n.getID(), new Node("n").getID());
    }
View Full Code Here

    }
   
    public void test__node_parent() {
      Document document = new Document("root");
      assertEquals(null, document.getRootNode().getParent());
      Node root = document.getRootNode();
      root.addChildNode("child");
      assertEquals(root, root.getNode("child").getParent());
    }
View Full Code Here

    assert(content.equals("Jee"));
  }

  private static void xmlWriterExample() {
    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

    TipuAPIClient api = null;
    try {
      api = new TipuAPIClientImple("https://h92.it.helsinki.fi/tipu-api", "tipuapi", "Barca4Valencia5Madrid6");

      TipuApiResource r = api.get(TipuAPIClient.SPECIES);
      Node helmipollo = r.getById("AEGFUN");
      String nimi_suomi = helmipollo.getNode("name").getContents();
      assert(nimi_suomi.equals("Helmipöllö"));
      String nimi_latina = "";
      for (Node n : helmipollo.getChildNodes("name")) {
        if (n.getAttribute("lang").equals("LA")) {
          nimi_latina = n.getContents();
          break;
        }
      }
View Full Code Here

public class XMLReader {

  public Document parse(String xml) {
    org.w3c.dom.Node domRootNode = getRoot(xml);
    Document d = new Document(domRootNode.getNodeName());
    Node documentRootNode = d.getRootNode();
    parse(domRootNode, documentRootNode);
    return d;
  }
View Full Code Here

    setAttributes(domNode, documentNode);
    NodeList childList = domNode.getChildNodes();
    for (int i=0; i<childList.getLength(); i++) {
      org.w3c.dom.Node domChildNode = childList.item(i);
      if (domChildNode.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
        Node documentChildNode = documentNode.addChildNode(domChildNode.getNodeName());
        parse(domChildNode, documentChildNode);
      }
      else if (domChildNode.getNodeType() == org.w3c.dom.Node.TEXT_NODE) {
        String contents = domChildNode.getTextContent().trim();
        if (contents.length() > 0) {
View Full Code Here

TOP

Related Classes of fi.luomus.commons.xml.Document.Node

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.