org.jaxen.SimpleNamespaceContext Java Examples

The following examples show how to use org.jaxen.SimpleNamespaceContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlConfiguration.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
public String getUniqueValue(String xPath) {
    SimpleNamespaceContext nsCtx = new SimpleNamespaceContext();
    nsCtx.addNamespace("ns", serverNamespace);
    try {
        XPath xp = new AXIOMXPath(xPath);
        xp.setNamespaceContext(nsCtx);
        OMElement elem = builder.getDocumentElement();
        if (elem != null) {
            List nodeList = xp.selectNodes(elem);
            Object obj;
            if (!nodeList.isEmpty() && ((obj = nodeList.get(0)) != null)) {
                return ((OMElement) obj).getText();
            }
        }
    } catch (JaxenException e) {
        throw new RuntimeException("XPath expression " + xPath + " failed", e);
    }
    return null;
}
 
Example #2
Source File: XmlConfiguration.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
public OMElement[] getElements(String xPath) {
    SimpleNamespaceContext nsCtx = new SimpleNamespaceContext();
    nsCtx.addNamespace("ns", serverNamespace);
    try {
        XPath xp = new AXIOMXPath(xPath);
        xp.setNamespaceContext(nsCtx);
        OMElement elem = builder.getDocumentElement();
        if (elem != null) {
            List nodeList = xp.selectNodes(elem);
            return (OMElement[]) nodeList.toArray(new OMElement[nodeList.size()]);
        }
    } catch (JaxenException e) {
        throw new RuntimeException("XPath expression " + xPath + " failed", e);
    }
    return new OMElement[0];
}