Package nu.xom

Examples of nu.xom.Text


                    sb.append(nextChild.getValue());
                    parent.removeChild(nextChild);
                    if (i+1 == parent.getChildCount()) break;
                }
                if (sb.length() == 0) parent.removeChild(child);
                else parent.replaceChild(child, new Text(sb.toString()));
            }
            else if (child instanceof Element) {
                merge((ParentNode) child);
            }
        }
View Full Code Here


      Comment comment = new Comment(
       "An example from Chapter 10 of Processing XML with Java");
      doc.insertChild(comment, doc.indexOf(root));
      Element desc = new Element("desc", "http://www.w3.org/2000/svg");
      root.appendChild(desc);
      Text descText = new Text("An example from Processing XML with Java");
      desc.appendChild(descText);
     
      // Serialize the document onto System.out
      System.out.println(doc.toXML());
       
View Full Code Here

   
   
    protected void setUp() {
        empty = new Element("Empty");
        notEmpty = new Element("NotEmpty");
        child = new Text("Hello");
        notEmpty.appendChild(child);
    }
View Full Code Here

    }

   
    public void testDetach() {
       
        Text text = new Text("This will be attached then detached");
        empty.appendChild(text);
        assertEquals(empty, text.getParent());
        text.detach();
        assertNull(text.getParent());
       
    }
View Full Code Here

   
    public void testIndexOf() {
       
        Element child1 = new Element("old1");
        Text child2 = new Text("old2");
        Comment child3 = new Comment("old3");
       
        assertEquals(-1, empty.indexOf(child1));       
       
        empty.appendChild(child1);
        empty.appendChild(child2);
        empty.appendChild(child3);
       
        assertEquals(0, empty.indexOf(child1));
        assertEquals(1, empty.indexOf(child2));
        assertEquals(2, empty.indexOf(child3));
        assertEquals(-1, empty.indexOf(empty));
        assertEquals(-1, empty.indexOf(new Text("test")));

    }
View Full Code Here

    // can't remove when insertion is legal;
    // succeeed or fail as unit
    public void testReplaceChildAtomicity() {
       
        Element parent = new Element("parent");
        Text child = new Text("child");
        parent.appendChild(child);
       
        try {
            parent.replaceChild(child, new DocType("root"));
            fail("allowed doctype child of element");
        }
        catch (IllegalAddException success) {
            assertEquals(parent, child.getParent());
            assertEquals(1, parent.getChildCount());
        }
       
        Element e = new Element("e");
        Text child2 = new Text("child2");
        e.appendChild(child2);
        try {
            parent.replaceChild(child, child2);
            fail("allowed replacement with existing parent");
        }
        catch (MultipleParentException success) {
            assertEquals(e, child2.getParent());
            assertEquals(parent, child.getParent());
            assertEquals(1, parent.getChildCount());
            assertEquals(1, e.getChildCount());
        }
       
View Full Code Here

        File stylesheet = new File(inputDir, "identity.xsl");
        Builder builder = new Builder();
        Document stylesheetDoc = builder.build(stylesheet);
        XSLTransform xform = new XSLTransform(stylesheetDoc);
        Element root = new Element("root", "http://www.example.org");
        root.appendChild(new Text("some data"));
        root.appendChild(new Element("something"));
        root.addAttribute(new Attribute("test", "test"));
        root.addAttribute(new Attribute("pre:red", "http://www.red.com/", "value"));
        Document input = new Document(root);
        Nodes output = xform.transform(input);
View Full Code Here

        Nodes output = xform.transform(input);
        assertEquals(6, output.size());
        assertEquals(element1, output.get(0));
        assertEquals(element2, output.get(1));
        assertEquals(new Element("element4"), output.get(3));
        assertEquals(new Text("test"), output.get(4));
        assertEquals(new ProcessingInstruction("test",
          "PIs are not treated as literals in XSLT?"), output.get(5));
       
    }   
View Full Code Here

        Document stylesheetDoc = builder.build(stylesheet);
        XSLTransform xform = new XSLTransform(stylesheetDoc);
        Document input = builder.build(doc);
        Nodes output = xform.transform(input);
        assertEquals(1, output.size());
        Text data = (Text) (output.get(0));
        assertEquals("Data", data.getValue());
       
    }
View Full Code Here

        Comment comment = new Comment("data");
        ProcessingInstruction pi = new ProcessingInstruction("target", "data");
        input.append(comment);
        input.append(root);
        input.append(pi);
        input.append(new Text("text"));
        try {
            XSLTransform.toDocument(new Nodes());
            fail("Converted text to document");
        }
        catch (XMLException success) {
View Full Code Here

TOP

Related Classes of nu.xom.Text

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.