Пример #1
0
  public void test_sharedSchemaXML() throws Exception {

    String xml =
        "<SharedSchemas>\n"
            + "<Schema Name=\"schedule.xsd\">\n<![CDATA[\n"
            + "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n"
            + "<xs:element name=\"Schedule\" type=\"ScheduleType\"/>\n"
            + "<xs:complexType name=\"ScheduleType\">\n"
            + "<xs:sequence>\n"
            + "<xs:element name=\"name\" type=\"xs:string\"/>\n"
            + "<xs:element name=\"size\" type=\"xs:integer\"/>\n"
            + "</xs:sequence>\n"
            + "</xs:complexType>\n"
            + "</xs:schema>"
            + "]]></Schema>\n"
            + "<Schema Name=\"rule.xsd\"><![CDATA[\n"
            + "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n"
            + "<xs:element name=\"Rule\" type=\"RuleType\"/>\n"
            + "<xs:complexType name=\"RuleType\">\n"
            + "<xs:sequence>\n"
            + "<xs:element name=\"id\" type=\"xs:integer\"/>\n"
            + "<xs:element name=\"name\" type=\"xs:string\"/>\n"
            + "</xs:sequence>\n"
            + "</xs:complexType>\n"
            + "</xs:schema>"
            + "]]></Schema>\n"
            + "</SharedSchemas>\n";

    System.out.println(
        "The value: " + xmlRoot.getNode("SharedSchemas/Schema?Name=schedule.xsd").getValue());

    XMLNode xmlRoot = XMLTreeBuilder.buildXMLTree(xml);
    System.out.println(xmlRoot.getXML(true));
  }
Пример #2
0
  public void test_clone() throws Exception {
    String xml = "<test><T1>vt1</T1><T2><T3 id=\"1\">vt3</T3><T4>vt4</T4></T2></test>";
    XMLNode xmlRoot = XMLTreeBuilder.buildXMLTree(xml);

    XMLNode clonedXmlRoot = (XMLNode) xmlRoot.clone();
    xmlRoot.setValue("test/T1", "Modified in root");

    XMLNode y = xmlRoot.getNode("test/T2/T3?id=1");
    y.addAttribute("id", "2");

    clonedXmlRoot.setValue("test/T1", "Modified in clone");
    XMLNode x = clonedXmlRoot.getNode("test/T2/T3?id=1");
    x.addAttribute("id", "3");

    clonedXmlRoot.deleteTree("test/T2/T4");

    System.out.println("Originnal XML: " + xmlRoot.getXML());
    System.out.println("Cloned XML: " + clonedXmlRoot.getXML());

    String newXML =
        "<test><T1>From the merged</T1><T5>valt5</T5><T2><T4>changed from merge</T4></T2></test>";
    //        clonedXmlRoot.merge(XMLTreeBuilder.buildXMLTree(newXML));

    clonedXmlRoot.merge(new XMLNode(XMLNode.ROOT, null));
    System.out.println("Originnal XML: " + xmlRoot.getXML());
    System.out.println("Cloned XML: " + clonedXmlRoot.getXML());
  }
Пример #3
0
  public void test_merge() throws Exception {
    String xml =
        "<test><t1 id=\"1\">valt1</t1><t1 id=\"2\">"
            + "<t6>valt6</t6><t7>valt7</t7></t1><t2>t2_val1</t2><t2>t2_val2</t2></test>";
    XMLNode xmlRoot = XMLTreeBuilder.buildXMLTree(xml);
    xmlRoot.merge(
        XMLTreeBuilder.buildXMLTree(
            "<test><t1 id=\"2\"><t6>changed value</t6><t8>val8</t8></t1><t2>t2_val2</t2><t4><t5>val t5</t5></t4></test>"));
    System.out.println(xmlRoot.getXML(true));
    XMLNode node = xmlRoot.getNode("test/t1?id=2/t6");
    System.out.println(node.getXML(true));

    node = xmlRoot.getNode("test/t4");
    System.out.println(node.getXML(true));

    LinkedList list = xmlRoot.getNodeList("test/t1?id=2/t6");
    System.out.println("size:" + list.size());
  }
Пример #4
0
 public void test_addUniqNode() throws Exception {
   String xml =
       "<test><t1 id=\"1\">valt1</t1><t1 id=\"2\">"
           + "<t6>valt6</t6><t7>valt7</t7></t1><t2>t2_val1</t2><t2>t2_val2</t2></test>";
   XMLNode xmlRoot = XMLTreeBuilder.buildXMLTree(xml);
   xmlRoot.addUniqNode("test", new XMLNode("t2", "t2_val1"), false);
   System.out.println(xmlRoot.getXML());
   xmlRoot.addUniqNode("test", new XMLNode("t2", "t2_val3"), false);
   System.out.println(xmlRoot.getXML());
 }
Пример #5
0
 public void test_CDATAxml() throws Exception {
   String xml =
       "<Test><t1> \n<![CDATA[\\nThis is a cdata <A>\n</B>]]></t1><t3>valt3</t3><t2> \n"
           + "<![CDATA[\n"
           + "This is a cdata <A>\n"
           + "</B\n"
           + " >]]></t2></Test>";
   XMLNode xmlRoot = XMLTreeBuilder.buildXMLTree(xml);
   System.out.println(xmlRoot.getXML(true));
 }
Пример #6
0
  public void test_getMap() throws Exception {
    String xml =
        "<SubscriptionData><Title>Test XML Title</Title><DeliveryPrefs><Online>1</Online></DeliveryPrefs>"
            + "<Topic name='SF-Giants'><TeamName>San Francisco</TeamName></Topic>"
            + "<Topic name='Oakland-As'><TeamName>Oakland</TeamName></Topic>"
            + "</SubscriptionData>";

    XMLNode xmlRoot = XMLTreeBuilder.buildXMLTree(xml);

    HashMap m = xmlRoot.getMap();
    Iterator i = m.keySet().iterator();
    System.out.println("MAP Keys:");
    while (i.hasNext()) {
      String key = (String) i.next();
      System.out.println("Key=" + key);
    }
  }
Пример #7
0
  public void test_getPath() throws Exception {
    String xml =
        "<SubscriptionData><Title>Test XML Title</Title><DeliveryPrefs><Online>1</Online></DeliveryPrefs>"
            + "<Topic name='SF-Giants'><TeamName>San Francisco</TeamName></Topic>"
            + "<Topic name='Oakland-As'><TeamName>Oakland</TeamName></Topic>"
            + "</SubscriptionData>";

    XMLNode xmlRoot = XMLTreeBuilder.buildXMLTree(xml);
    System.out.println(
        "value:" + xmlRoot.getValue("SubscriptionData/Topic?name=SF-Giants/TeamName"));
    xmlRoot.setValue("SubscriptionData/Topic?name=SF-Giants/TeamName", "changed SFO");
    System.out.println(
        "value:" + xmlRoot.getValue("SubscriptionData/Topic?name=SF-Giants/TeamName"));
    XMLNode n = xmlRoot.getNode("SubscriptionData/Topic?name=SF-Giants/TeamName");
    System.out.println("Path: " + n.getPath());
    n = xmlRoot.getNode("SubscriptionData/Title");
    System.out.println("Path: " + n.getPath());
    n = xmlRoot.getNode("SubscriptionData/Topic?name=SF-Giants");
    System.out.println("Path: " + n.getPath());
  }
Пример #8
0
 protected void setUp() throws Exception {
   super.setUp();
   xmlRoot = XMLTreeBuilder.buildXMLTree(testxml);
 }