Package nu.xom

Examples of nu.xom.XPathContext


        Element child = new Element("child", "http://www.example.org");
        parent.appendChild(child);
       
        Element test = new Element("test");
        test.addAttribute(new Attribute("pre:test", "http://www.example.org", "value"));
        XPathContext context = XPathContext.makeNamespaceContext(test);
        Nodes result = parent.query("child::pre:child", context);
        assertEquals(1, result.size());
        assertEquals(child, result.get(0));  
       
    }
View Full Code Here


        Element child = new Element("child", "http://www.example.org");
        parent.appendChild(child);
       
        Element test = new Element("test");
        test.addNamespaceDeclaration("pre", "http://www.example.org");
        XPathContext context = XPathContext.makeNamespaceContext(test);
        Nodes result = parent.query("child::pre:child", context);
        assertEquals(1, result.size());
        assertEquals(child, result.get(0));  
       
    }
View Full Code Here

        parent.appendChild(child);
       
        Element test = new Element("pre:test", "http://www.example.org");
        Element testChild = new Element("testchild");
        test.appendChild(testChild);
        XPathContext context = XPathContext.makeNamespaceContext(testChild);
        Nodes result = parent.query("child::pre:child", context);
        assertEquals(1, result.size());
        assertEquals(child, result.get(0));  
       
    }
View Full Code Here

       
        Element test = new Element("test");
        test.addAttribute(new Attribute("pre:test", "http://www.example.org", "value"));
        Element testChild = new Element("testchild");
        test.appendChild(testChild);
        XPathContext context = XPathContext.makeNamespaceContext(testChild);
        Nodes result = parent.query("child::pre:child", context);
        assertEquals(1, result.size());
        assertEquals(child, result.get(0));  
       
    }
View Full Code Here

       
        Element test = new Element("test");
        test.addNamespaceDeclaration("pre", "http://www.example.org");
        Element testChild = new Element("testchild");
        test.appendChild(testChild);
        XPathContext context = XPathContext.makeNamespaceContext(testChild);
        Nodes result = parent.query("child::pre:child", context);
        assertEquals(1, result.size());
        assertEquals(child, result.get(0));  
       
    }
View Full Code Here

        Element child = new Element("b:child", "http://www.example.org");
        Attribute att = new Attribute("c:dog", "http://www.cafeconleche.org/", "test");
        parent.appendChild(child);
        child.addAttribute(att);
       
        XPathContext context = new XPathContext("pre", "http://www.example.org");
        context.addNamespace("c", "http://www.cafeconleche.org/");
        Nodes result = parent.query("child::pre:child", context);
        assertEquals(1, result.size());
        assertEquals(child, result.get(0));
       
        result = child.query("@c:*", context);
View Full Code Here

        Element child = new Element("child", "http://www.example.org");
        parent.appendChild(child);
        child.appendChild("1");
        child.appendChild("2");
       
        XPathContext context = new XPathContext("pre", "http://www.example.org");
        Nodes result = parent.query("descendant::text()", context);
        assertEquals(2, result.size());
        assertEquals("1", result.get(0).getValue());  
        assertEquals("2", result.get(1).getValue());  
       
View Full Code Here

                // because XOM doesn't support variables in
                // 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++) {
View Full Code Here

    }


    private XPathContext getXPathContext(Element contextElement) {

        XPathContext context = new XPathContext();
        for (int i = 0; i < contextElement.getNamespaceDeclarationCount(); i++) {
            String prefix = contextElement.getNamespacePrefix(i);
            if (! "".equals(prefix)) {
                context.addNamespace(prefix, contextElement.getNamespaceURI(prefix));
            }
        }
        return context;
    }
View Full Code Here

    List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
    XSLTransform schematronTransform = Util.buildSchematronTransform(schematronFile);
    Nodes nodes = schematronTransform.transform(new Document(getXOMElementCopy()));
    Document doc = XSLTransform.toDocument(nodes);

    XPathContext context = XPathContext.makeNamespaceContext(doc.getRootElement());
    String svrlNamespace = context.lookup("svrl");
    Nodes outputNodes = doc.query("//svrl:failed-assert | //svrl:successful-report", context);
    for (int i = 0; i < outputNodes.size(); i++) {
      if (outputNodes.get(i) instanceof Element) {
        Element outputElement = (Element) outputNodes.get(i);
        boolean isAssert = "failed-assert".equals(outputElement.getLocalName());
View Full Code Here

TOP

Related Classes of nu.xom.XPathContext

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.