예제 #1
0
 public void test_XMLNode_convert() {
   String xmlstr =
       "<annotation>\n"
           + "  <test xmlns=\"http://test.org/\" id=\"test\">test</test>\n"
           + "</annotation>";
   XMLNode node;
   XMLNode child, gchild;
   XMLAttributes attr;
   XMLNamespaces ns;
   node = XMLNode.convertStringToXMLNode(xmlstr, null);
   child = node.getChild(0);
   gchild = child.getChild(0);
   attr = child.getAttributes();
   ns = child.getNamespaces();
   assertTrue(!node.getName().equals("annotation") == false);
   assertTrue(!child.getName().equals("test") == false);
   assertTrue(!gchild.getCharacters().equals("test") == false);
   assertTrue(!attr.getName(0).equals("id") == false);
   assertTrue(!attr.getValue(0).equals("test") == false);
   assertTrue(!ns.getURI(0).equals("http://test.org/") == false);
   assertTrue(ns.getPrefix(0).equals("") == true);
   String toxmlstring = node.toXMLString();
   assertTrue(!toxmlstring.equals(xmlstr) == false);
   node = null;
 }
예제 #2
0
 public void test_XMLNode_convert_dummyroot() {
   String xmlstr_nodummy1 = "<notes>\n" + "  <p>test</p>\n" + "</notes>";
   String xmlstr_nodummy2 = "<html>\n" + "  <p>test</p>\n" + "</html>";
   String xmlstr_nodummy3 = "<body>\n" + "  <p>test</p>\n" + "</body>";
   String xmlstr_nodummy4 = "<p>test</p>";
   String xmlstr_nodummy5 = "<test1>\n" + "  <test2>test</test2>\n" + "</test1>";
   String xmlstr_dummy1 = "<p>test1</p><p>test2</p>";
   String xmlstr_dummy2 = "<test1>test1</test1><test2>test2</test2>";
   XMLNode rootnode;
   XMLNode child, gchild;
   XMLAttributes attr;
   XMLNamespaces ns;
   String toxmlstring;
   rootnode = XMLNode.convertStringToXMLNode(xmlstr_nodummy1, null);
   assertTrue(rootnode.getNumChildren() == 1);
   child = rootnode.getChild(0);
   gchild = child.getChild(0);
   assertTrue(!rootnode.getName().equals("notes") == false);
   assertTrue(!child.getName().equals("p") == false);
   assertTrue(!gchild.getCharacters().equals("test") == false);
   toxmlstring = rootnode.toXMLString();
   assertTrue(!toxmlstring.equals(xmlstr_nodummy1) == false);
   rootnode = null;
   rootnode = XMLNode.convertStringToXMLNode(xmlstr_nodummy2, null);
   assertTrue(rootnode.getNumChildren() == 1);
   child = rootnode.getChild(0);
   gchild = child.getChild(0);
   assertTrue(!rootnode.getName().equals("html") == false);
   assertTrue(!child.getName().equals("p") == false);
   assertTrue(!gchild.getCharacters().equals("test") == false);
   toxmlstring = rootnode.toXMLString();
   assertTrue(!toxmlstring.equals(xmlstr_nodummy2) == false);
   rootnode = null;
   rootnode = XMLNode.convertStringToXMLNode(xmlstr_nodummy3, null);
   assertTrue(rootnode.getNumChildren() == 1);
   child = rootnode.getChild(0);
   gchild = child.getChild(0);
   assertTrue(!rootnode.getName().equals("body") == false);
   assertTrue(!child.getName().equals("p") == false);
   assertTrue(!gchild.getCharacters().equals("test") == false);
   toxmlstring = rootnode.toXMLString();
   assertTrue(!toxmlstring.equals(xmlstr_nodummy3) == false);
   rootnode = null;
   rootnode = XMLNode.convertStringToXMLNode(xmlstr_nodummy4, null);
   assertTrue(rootnode.getNumChildren() == 1);
   child = rootnode.getChild(0);
   assertTrue(!rootnode.getName().equals("p") == false);
   assertTrue(!child.getCharacters().equals("test") == false);
   toxmlstring = rootnode.toXMLString();
   assertTrue(!toxmlstring.equals(xmlstr_nodummy4) == false);
   rootnode = null;
   rootnode = XMLNode.convertStringToXMLNode(xmlstr_nodummy5, null);
   assertTrue(rootnode.getNumChildren() == 1);
   child = rootnode.getChild(0);
   gchild = child.getChild(0);
   assertTrue(!rootnode.getName().equals("test1") == false);
   assertTrue(!child.getName().equals("test2") == false);
   assertTrue(!gchild.getCharacters().equals("test") == false);
   toxmlstring = rootnode.toXMLString();
   assertTrue(!toxmlstring.equals(xmlstr_nodummy5) == false);
   rootnode = null;
   rootnode = XMLNode.convertStringToXMLNode(xmlstr_dummy1, null);
   assertTrue(rootnode.isEOF() == true);
   assertTrue(rootnode.getNumChildren() == 2);
   child = rootnode.getChild(0);
   gchild = child.getChild(0);
   assertTrue(!child.getName().equals("p") == false);
   assertTrue(!gchild.getCharacters().equals("test1") == false);
   child = rootnode.getChild(1);
   gchild = child.getChild(0);
   assertTrue(!child.getName().equals("p") == false);
   assertTrue(!gchild.getCharacters().equals("test2") == false);
   toxmlstring = rootnode.toXMLString();
   assertTrue(!toxmlstring.equals(xmlstr_dummy1) == false);
   rootnode = null;
   rootnode = XMLNode.convertStringToXMLNode(xmlstr_dummy2, null);
   assertTrue(rootnode.isEOF() == true);
   assertTrue(rootnode.getNumChildren() == 2);
   child = rootnode.getChild(0);
   gchild = child.getChild(0);
   assertTrue(!child.getName().equals("test1") == false);
   assertTrue(!gchild.getCharacters().equals("test1") == false);
   child = rootnode.getChild(1);
   gchild = child.getChild(0);
   assertTrue(!child.getName().equals("test2") == false);
   assertTrue(!gchild.getCharacters().equals("test2") == false);
   toxmlstring = rootnode.toXMLString();
   assertTrue(!toxmlstring.equals(xmlstr_dummy2) == false);
   rootnode = null;
 }