Package org.jaxen

Examples of org.jaxen.SimpleNamespaceContext


        Map<String, String> mapNs = metadataSchema.getSchemaNSWithPrefix();


        try {
            JDOMXPath xpath = new JDOMXPath(xpathProperty);
            xpath.setNamespaceContext(new SimpleNamespaceContext(mapNs));
            // Select the node to update and check it exists
            return SelectResult.of(xpath.selectSingleNode(metadataRecord));
        } catch (JaxenException e) {
            Log.warning(Geonet.EDITORADDELEMENT, "An illegal xpath was used to locate an element: " + xpathProperty);
            return SelectResult.ERROR;
View Full Code Here


        doc.appendChild(a);
        Element b = doc.createElementNS("http://www.b.com/", "b:bar");
        a.appendChild(b);
       
        XPath xpath = new DOMXPath("/a:foo/b:bar/namespace::*/parent::*");
        SimpleNamespaceContext context1 = new SimpleNamespaceContext();
        context1.addNamespace("a", "http://www.a.com/");
        context1.addNamespace("b", "http://www.b.com/");
        xpath.setNamespaceContext(context1);
        List result = xpath.selectNodes(doc);
        assertEquals(1, result.size());
        assertEquals(b, result.get(0));
  
View Full Code Here

    public void testQueryDefaultNamespaceWithContext() throws JaxenException {
       
        Element root = doc.createElementNS("http://www.example.org/", "root");
        doc.appendChild(root);
        XPath xpath = new DOMXPath("/pre:root");
        SimpleNamespaceContext context = new SimpleNamespaceContext();
        context.addNamespace("pre", "http://www.example.org/");
        xpath.setNamespaceContext(context);
        List result = xpath.selectNodes(root);
        assertEquals(1, result.size());
  
    }  
View Full Code Here

    // Implementation methods
    // -------------------------------------------------------------------------
    protected void testXPath(String xpathText) {
        XPath xpath = DocumentHelper.createXPath(xpathText);

        SimpleNamespaceContext context = new SimpleNamespaceContext();
        context.addNamespace("xplt", "www.xxxx.com");
        context.addNamespace("xpl", "www.xxxx.com");
        xpath.setNamespaceContext(context);

        List list = xpath.selectNodes(document);

        log("Searched path: " + xpathText + " found: " + list.size()
View Full Code Here

        XPath xpath = getXPath(xpathString);
        return (OMElement) xpath.selectSingleNode(parentElement);
    }

    private XPath getXPath(String xpathString) throws JaxenException {
        SimpleNamespaceContext nsCtx = new SimpleNamespaceContext();
        nsCtx.addNamespace("ns", "http://geronimo.apache.org/xml/ns/j2ee/connector-1.1");
        XPath xpath = new AXIOMXPath(xpathString);
        xpath.setNamespaceContext(nsCtx);
        return xpath;
    }
View Full Code Here

            if (log.isDebugEnabled()) {
                log.debug( "Setting the namespace context to be: " + uris );
            }

            xpath.setNamespaceContext( new SimpleNamespaceContext( this.uris ) );

            return xpath;
        }
        catch (JaxenException e)
        {
View Full Code Here

            throw new FactoryException(e);
        }
    }

    protected NamespaceContext createNamespaceContext(Configuration configuration) {
        SimpleNamespaceContext answer = new SimpleNamespaceContext();
        String[] names = configuration.getAttributeNames();
        for (int i = 0; i < names.length; i++) {
            String name = names[i];
            if (name.equals("xmlns")) {
                answer.addNamespace("", configuration.getAttribute(name));
            }
            else {
                if (name.startsWith("xmlns:")) {
                    String prefix = name.substring(6);
                    String uri = configuration.getAttribute(name);
                    answer.addNamespace(prefix, uri);
                }
            }
        }
        return answer;
    }
View Full Code Here

  private static List findElements(OMElement elem, String expression) throws WSSecurityException {
    try {
      XPath xp = new AXIOMXPath(expression);
     
      //Set namespaces
      SimpleNamespaceContext nsCtx = new SimpleNamespaceContext();
      nsCtx.addNamespace(WSConstants.ENC_PREFIX,WSConstants.ENC_NS);
      nsCtx.addNamespace(WSConstants.SIG_PREFIX,WSConstants.SIG_NS);
      nsCtx.addNamespace(WSConstants.WSSE_PREFIX,WSConstants.WSSE_NS);
      nsCtx.addNamespace(WSConstants.WSU_PREFIX,WSConstants.WSU_NS);
     
      xp.setNamespaceContext(nsCtx);
     
      return xp.selectNodes(elem);
     
View Full Code Here

public class XPathEvaluator {

    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);
    }
View Full Code Here

        XPath xpath = getXPath(xpathString);
        return (OMElement) xpath.selectSingleNode(parentElement);
    }

    private XPath getXPath(String xpathString) throws JaxenException {
        SimpleNamespaceContext nsCtx = new SimpleNamespaceContext();
        nsCtx.addNamespace("ns", "http://geronimo.apache.org/xml/ns/j2ee/connector-1.1");
        XPath xpath = new AXIOMXPath(xpathString);
        xpath.setNamespaceContext(nsCtx);
        return xpath;
    }
View Full Code Here

TOP

Related Classes of org.jaxen.SimpleNamespaceContext

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.