Search in sources :

Example 1 with AXIOMXPath

use of org.apache.axiom.om.xpath.AXIOMXPath in project webservices-axiom by apache.

the class TestAddNamespaces method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement root1 = AXIOMUtil.stringToOM(factory, "<ns1:root xmlns:ns1='urn:ns1'><ns1:child xmlns:ns2='urn:ns2'/></root>");
    OMElement root2 = AXIOMUtil.stringToOM(factory, "<root xmlns='urn:ns1'><child xmlns='urn:ns2'>text</child></root>");
    AXIOMXPath xpath = new AXIOMXPath("/ns1:root/ns2:child");
    xpath.addNamespaces(root1.getFirstElement());
    assertEquals("text", xpath.stringValueOf(root2.getParent()));
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMElement(org.apache.axiom.om.OMElement) AXIOMXPath(org.apache.axiom.om.xpath.AXIOMXPath)

Example 2 with AXIOMXPath

use of org.apache.axiom.om.xpath.AXIOMXPath in project webservices-axiom by apache.

the class TestAddNamespaces2 method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement root1 = AXIOMUtil.stringToOM(factory, "<ns:root xmlns:ns='urn:ns1'><ns:child xmlns:ns='urn:ns2'/></root>");
    OMElement root2 = AXIOMUtil.stringToOM(factory, "<root xmlns='urn:ns1'><child xmlns='urn:ns2'>text</child></root>");
    AXIOMXPath xpath = new AXIOMXPath("//ns:child");
    xpath.addNamespaces(root1.getFirstElement());
    assertEquals("text", xpath.stringValueOf(root2.getParent()));
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMElement(org.apache.axiom.om.OMElement) AXIOMXPath(org.apache.axiom.om.xpath.AXIOMXPath)

Example 3 with AXIOMXPath

use of org.apache.axiom.om.xpath.AXIOMXPath in project webservices-axiom by apache.

the class TestGetAttributeQName method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement("test", null);
    element.addAttribute("att", "value", factory.createOMNamespace("urn:test", "p"));
    assertEquals("p:att", new AXIOMXPath("name(@*)").stringValueOf(element));
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMElement(org.apache.axiom.om.OMElement) AXIOMXPath(org.apache.axiom.om.xpath.AXIOMXPath)

Example 4 with AXIOMXPath

use of org.apache.axiom.om.xpath.AXIOMXPath in project webservices-axiom by apache.

the class XPathEvaluator method evaluateXpath.

public List evaluateXpath(String xpathExpression, Object element, String nsURI) throws Exception {
    AXIOMXPath xpath = new AXIOMXPath(xpathExpression);
    if (nsURI != null) {
        SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
        nsContext.addNamespace(null, nsURI);
        xpath.setNamespaceContext(nsContext);
    }
    return xpath.selectNodes(element);
}
Also used : SimpleNamespaceContext(org.jaxen.SimpleNamespaceContext) AXIOMXPath(org.apache.axiom.om.xpath.AXIOMXPath)

Example 5 with AXIOMXPath

use of org.apache.axiom.om.xpath.AXIOMXPath in project webservices-axiom by apache.

the class TestXPathAppliedToSOAPEnvelope method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement elem1 = soapFactory.createOMElement("elem1", null);
    OMElement elem2 = soapFactory.createOMElement("elem2", null);
    OMElement elem3 = soapFactory.createOMElement("elem3", null);
    elem2.addChild(elem3);
    elem1.addChild(elem2);
    SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
    envelope.getBody().addChild(elem1);
    if (createDocument) {
        soapFactory.createOMDocument().addChild(envelope);
    }
    String XPathString = "//elem1";
    AXIOMXPath XPath = new AXIOMXPath(XPathString);
    OMNode node = (OMNode) XPath.selectSingleNode(envelope);
    assertNotNull(node);
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) AXIOMXPath(org.apache.axiom.om.xpath.AXIOMXPath)

Aggregations

AXIOMXPath (org.apache.axiom.om.xpath.AXIOMXPath)5 OMElement (org.apache.axiom.om.OMElement)4 OMFactory (org.apache.axiom.om.OMFactory)3 OMNode (org.apache.axiom.om.OMNode)1 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)1 SimpleNamespaceContext (org.jaxen.SimpleNamespaceContext)1