Package nu.xom

Examples of nu.xom.Node


        Elements inputs = root.getChildElements("document");
        Element input = inputs.get(1);
        Document html = new Document(new Element("fake"));
        int p = 0;
        while (true) {
            Node node = input.getChild(0);
            if (node instanceof Element) break;
            else {
                node.detach();
                if (node instanceof Text) continue;
                html.insertChild(node, p++);
            }
        }   
        Node newroot = input.getChild(0);
        newroot.detach();
        html.setRootElement((Element) newroot);
        while (input.getChildCount() > 0) {
            Node node = input.getChild(0);
            node.detach();
            if (node instanceof Text) continue;
            html.appendChild(node);
        }   
       
        Nodes doc2Queries = root.query("child::query[starts-with(@id, 'A')]");
       
        XPathContext context = new XPathContext();
        context.addNamespace("svg", "http://www.w3.org/2000/svg");
        context.addNamespace("xlink", "http://www.w3.org/1999/xlink");
       
        for (int i = 0; i < doc2Queries.size(); i++) {
            Element query = (Element) doc2Queries.get(i);
            String xpath = query.getFirstChildElement("syntax").getValue();
            String id = query.getAttributeValue("id");

            Nodes result = html.query(xpath, context);
            Element answer = query.getFirstChildElement("answer");
            Nodes expected = new Nodes();
            for (int j = 0; j < answer.getChildCount(); j++) {
                Node node = answer.getChild(j);
                if (node instanceof Text) {
                    if (!("".equals(node.getValue().trim()))) {
                        expected.append(node);
                    }
                }
                else {
                    expected.append(node);
                }
            }
            assertEquals("Failed query " + id, expected.size(), result.size());
            for (int j = 0; j < result.size(); j++) {
                Node expectedNode = expected.get(j);
                Node actualNode = result.get(j);               
                assertEquals(id + " " + expectedNode.toXML() + " "
                  + actualNode.toXML(), expectedNode, actualNode);
            }
        }
       
    }
View Full Code Here


   

    public void testSelfAxisWithTextChild() {
       
        Element parent = new Element("parent");
        Node child = new Text("child");
        parent.appendChild(child);
        Nodes result = child.query("self::text()");
        assertEquals(1, result.size());
        assertEquals(child, result.get(0));
       
    }
View Full Code Here

   

    public void testSelfAxisWithTextChildren() {
       
        Element parent = new Element("parent");
        Node child1 = new Text("1");
        Node child2 = new Text("2");
        Node child3 = new Text("3");
        Node child4 = new Text("4");
        parent.appendChild(child1);
        parent.appendChild(child2);
        parent.appendChild(child3);
        parent.appendChild(child4);
        Nodes result = child1.query("self::text()");
View Full Code Here

   

    public void testSelfAxisWithTextChildren2() {
       
        Element parent = new Element("parent");
        Node child1 = new Text("1");
        Node child2 = new Text("2");
        Node child3 = new Text("3");
        Node child4 = new Text("4");
        parent.appendChild(child1);
        parent.appendChild(child2);
        parent.appendChild(child3);
        parent.appendChild(child4);
        Nodes result = child3.query("self::text()");
View Full Code Here

    }
   

    public void testSelfAxisWithTextChildAndNoParent() {
       
        Node child = new Text("child");
        Nodes result = child.query("self::text()");
        assertEquals(1, result.size());
        assertEquals(child, result.get(0));
       
    }
View Full Code Here

                // XPath expressions
                if (queryUsesVars(contextElement)) continue;
               
                String xpath = contextElement.getAttributeValue("select");
                XPathContext namespaces = getXPathContext(contextElement);
                Node context = source.query(xpath).get(0);
               
                // process counts
                Elements tests = contextElement.getChildElements("test");
                for (int k = 0; k < tests.size(); k++) {
                    Element test = tests.get(k);
                   
                    String select = test.getAttributeValue("select");
                    Attribute countAttribute = test.getAttribute("count");
                    int count = -1;
                    if (countAttribute != null) {
                        count = Integer.parseInt(countAttribute.getValue());
                    }
                   
                    boolean exceptional = false;
                    String exception = test.getAttributeValue("exception");
                    if ("true".equals(exception)) {
                        exceptional = true;
                    }
                   
                    if (exceptional) {
                        try {
                            context.query(select, namespaces);
                            fail("Evaluated " + select);
                        }
                        catch (XPathException success) {
                            assertNotNull(success.getMessage());
                        }
                    }
                    else {
                        try {
                            Nodes results = context.query(select, namespaces);
                            if (count != -1) {
                                assertEquals(select, count, results.size());
                            }
                            Elements valueOfs = test.getChildElements("valueOf");
                            for (int v = 0; v < valueOfs.size(); v++) {
View Full Code Here

        assertEquals(1, result.size());
        Element a = (Element) result.get(0);
        assertEquals("a", a.getLocalName());
        assertEquals(1, a.getChildCount());
        assertEquals(0, a.getAttributeCount());
        Node child = a.getChild(0);
        assertTrue(child instanceof Comment);
        assertTrue(child.getValue().equals("test"));
       
    }
View Full Code Here

    }
   
   
    public void testCompareMismatchedTypes() {
    
        Node n1 = new Text("");
        Node n2 = new Attribute("name", "value");
       
        try {
            assertEquals(n1, n2);
            fail("Text equals Attribute?!");
        }
View Full Code Here

    }
   
   
    public void testCompareMismatchedNullNodeTypes() {
    
        Node n1 = new Text("");
        Node n2 = null;
       
        try {
            assertEquals(n1, n2);
            fail("Text equals null?!");
        }
View Full Code Here

    }
   
   
    public void testCompareAttributesAsNodes() {
    
        Node a1 = new Attribute("test", "value");
        Node a2 = a1.copy();
        assertEquals(a1, a2);
       
    }
View Full Code Here

TOP

Related Classes of nu.xom.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.