Search in sources :

Example 1 with DOMXPath

use of org.jaxen.dom.DOMXPath in project webservices-axiom by apache.

the class XPathTestBase method testid54614.

public void testid54614() throws JaxenException {
    Navigator nav = getNavigator();
    String url = "xml/moreover.xml";
    log("Document [" + url + "]");
    Object document = nav.getDocument(url);
    XPath contextpath = new BaseXPath("/", nav);
    log("Initial Context :: " + contextpath);
    List list = contextpath.selectNodes(document);
    Iterator iter = list.iterator();
    while (iter.hasNext()) {
        Object context = iter.next();
        assertCountXPath(1, context, "/child::node()");
        assertCountXPath(1, context, "/*");
        assertCountXPath(20, context, "/*/article");
        assertCountXPath(221, context, "//*");
        assertCountXPath(20, context, "//*[local-name()='article']");
        assertCountXPath(20, context, "//article");
        assertCountXPath(20, context, "/*/*[@code]");
        assertCountXPath(1, context, "/moreovernews/article[@code='13563275']");
        DOMXPath xpath = new DOMXPath("/moreovernews/article[@code='13563275']");
        List results = xpath.selectNodes(getContext(context));
        Object result = results.get(0);
        assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url");
        xpath = new DOMXPath("/*/article[@code='13563275']");
        results = xpath.selectNodes(getContext(context));
        result = results.get(0);
        assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url");
        xpath = new DOMXPath("//article[@code='13563275']");
        results = xpath.selectNodes(getContext(context));
        result = results.get(0);
        assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url");
        xpath = new DOMXPath("//*[@code='13563275']");
        results = xpath.selectNodes(getContext(context));
        result = results.get(0);
        assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url");
        xpath = new DOMXPath("/child::node()/child::node()[@code='13563275']");
        results = xpath.selectNodes(getContext(context));
        result = results.get(0);
        assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url");
        xpath = new DOMXPath("/*/*[@code='13563275']");
        results = xpath.selectNodes(getContext(context));
        result = results.get(0);
        assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url");
    }
}
Also used : DOMXPath(org.jaxen.dom.DOMXPath) DOMXPath(org.jaxen.dom.DOMXPath) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with DOMXPath

use of org.jaxen.dom.DOMXPath in project webservices-axiom by apache.

the class XPathTestBase method assertCountXPath2.

private Object assertCountXPath2(int expectedSize, Object context, String xpathStr) throws JaxenException {
    log(debug, "  Select :: " + xpathStr);
    DOMXPath xpath = new DOMXPath(xpathStr);
    List results = xpath.selectNodes(getContext(context));
    log(debug, "    Expected Size :: " + expectedSize);
    log(debug, "    Result Size   :: " + results.size());
    if (expectedSize != results.size()) {
        log(debug, "      ## FAILED");
        log(debug, "      ## xpath: " + xpath + " = " + xpath.debug());
        Iterator resultIter = results.iterator();
        while (resultIter.hasNext()) {
            log(debug, "      --> " + resultIter.next());
        }
    }
    assertEquals(xpathStr, expectedSize, results.size());
    assertExprGetTextIdempotent(xpath);
    if (expectedSize > 0) {
        return results.get(0);
    }
    return null;
}
Also used : DOMXPath(org.jaxen.dom.DOMXPath) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with DOMXPath

use of org.jaxen.dom.DOMXPath in project tdi-studio-se by Talend.

the class SoapExecutor method createXPath.

/**
     * Constructs XPath query over the SOAP message
     * @param query XPath query
     * @param response SOAP message
     * @return XPath query
     * @throws SOAPException in case of SOAP issue
     * @throws JaxenException XPath problem
     */
public XPath createXPath(String query, SOAPMessage response) throws SOAPException, JaxenException {
    //Uses DOM to XPath mapping
    XPath xpath = new DOMXPath(query);
    //Define a namespaces used in response
    SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
    SOAPPart sp = response.getSOAPPart();
    SOAPEnvelope env = sp.getEnvelope();
    SOAPBody bdy = env.getBody();
    //Add namespaces from SOAP envelope
    addNamespaces(nsContext, env);
    //Add namespaces of top body element
    Iterator bodyElements = bdy.getChildElements();
    while (bodyElements.hasNext()) {
        SOAPElement element = (SOAPElement) bodyElements.next();
        addNamespaces(nsContext, element);
    }
    xpath.setNamespaceContext(nsContext);
    return xpath;
}
Also used : XPath(org.jaxen.XPath) DOMXPath(org.jaxen.dom.DOMXPath) DOMXPath(org.jaxen.dom.DOMXPath) Iterator(java.util.Iterator) SimpleNamespaceContext(org.jaxen.SimpleNamespaceContext)

Example 4 with DOMXPath

use of org.jaxen.dom.DOMXPath in project webservices-axiom by apache.

the class XPathTestBase method assertValueOfXPath.

private void assertValueOfXPath(String expected, Object context, String xpathStr) throws JaxenException {
    DOMXPath xpath = new DOMXPath(xpathStr);
    Object node = xpath.evaluate(getContext(context));
    String result = StringFunction.evaluate(node, getNavigator());
    log(debug, "  Select :: " + xpathStr);
    log(debug, "    Expected :: " + expected);
    log(debug, "    Result   :: " + result);
    if (!expected.equals(result)) {
        log(debug, "      ## FAILED");
        log(debug, "      ## xpath: " + xpath + " = " + xpath.debug());
    }
    assertEquals(xpathStr, expected, result);
    assertExprGetTextIdempotent(xpath);
}
Also used : DOMXPath(org.jaxen.dom.DOMXPath)

Example 5 with DOMXPath

use of org.jaxen.dom.DOMXPath in project webservices-axiom by apache.

the class XPathTestBase method assertInvalidXPath.

private void assertInvalidXPath(Object context, String xpathStr) {
    try {
        log(debug, "  Select :: " + xpathStr);
        DOMXPath xpath = new DOMXPath(xpathStr);
        List results = xpath.selectNodes(getContext(context));
        log(debug, "    Result Size   :: " + results.size());
        fail("An exception was expected.");
    } catch (JaxenException e) {
        log(debug, "    Caught expected exception " + e.getMessage());
    }
}
Also used : DOMXPath(org.jaxen.dom.DOMXPath) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

DOMXPath (org.jaxen.dom.DOMXPath)6 List (java.util.List)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 XPath (org.jaxen.XPath)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 JaxenException (org.jaxen.JaxenException)1 SimpleNamespaceContext (org.jaxen.SimpleNamespaceContext)1 Document (org.w3c.dom.Document)1 SAXException (org.xml.sax.SAXException)1