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");
}
}
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;
}
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;
}
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);
}
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());
}
}
Aggregations