Example usage for org.jdom2.xpath XPath selectNodes

List of usage examples for org.jdom2.xpath XPath selectNodes

Introduction

In this page you can find the example usage for org.jdom2.xpath XPath selectNodes.

Prototype

abstract public List<?> selectNodes(Object context) throws JDOMException;

Source Link

Document

Evaluates the wrapped XPath expression and returns the list of selected items.

Usage

From source file:com.ardor3d.extension.model.collada.jdom.ColladaDOMUtil.java

License:Open Source License

/**
 * Select nodes through an XPath query and return all hits as a List
 * /*from  w w  w .j  a va  2 s  .  c  o m*/
 * @param element
 *            root element to start search on
 * @param query
 *            XPath expression
 * @return the list of selected items, which may be of types: {@link Element}, {@link Attribute}, {@link Text},
 *         {@link CDATA}, {@link Comment}, {@link ProcessingInstruction}, Boolean, Double, or String.
 */
public List<?> selectNodes(final Element element, final String query) {
    final XPath xPathExpression = getXPathExpression(query);

    try {
        return xPathExpression.selectNodes(element);
    } catch (final JDOMException e) {
        e.printStackTrace();
    }
    return Collections.emptyList();
}

From source file:egovframework.rte.fdl.xml.AbstractXMLUtility.java

License:Apache License

@SuppressWarnings("deprecation")
public List<?> getResult(Document doc, String exps) throws JDOMException {
    org.jdom2.xpath.XPath xPath = org.jdom2.xpath.XPath.newInstance(exps);
    return xPath.selectNodes(doc);
}

From source file:jpcsp.test.NIDInfo.java

License:Open Source License

@SuppressWarnings("deprecation")
public Firmware(String version, String psplibdoc_filename) throws Exception {
    m_version = version;/*from   w  w w . j av  a  2  s . co  m*/
    m_moduleCount = 0;
    m_functionCount = 0;
    m_moduleTable = new Hashtable<String, Module>();

    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(new File(psplibdoc_filename));

    XPath modules = XPath.newInstance("/PSPLIBDOC/PRXFILES/PRXFILE/LIBRARIES/LIBRARY");

    List<?> LibList = modules.selectNodes(doc);
    //m_moduleList = modules.selectNodes(doc, "//NAME");

    Iterator<?> i = LibList.iterator();

    while (i.hasNext()) {
        Element curEl = (Element) i.next();
        String modName = curEl.getChild("NAME").getText();
        Module newMod = new Module(modName);
        List<?> FunctionList = curEl.getChild("FUNCTIONS").getChildren("FUNCTION");
        Iterator<?> j = FunctionList.iterator();
        while (j.hasNext()) {
            Element funcEl = (Element) j.next();
            newMod.addFunction(funcEl.getChild("NID").getText(), funcEl.getChild("NAME").getText());
            m_functionCount++;
        }
        m_moduleCount++;
        m_moduleTable.put(modName, newMod);
    }

    System.out.println("filename: " + psplibdoc_filename + " modules: " + m_moduleCount + " functions: "
            + m_functionCount);
}

From source file:org.jahia.utils.osgi.parsers.AbstractXmlFileParser.java

License:Open Source License

public List<?> selectNodes(Element scopeElement, String xPathExpression) throws JDOMException {
    XPath xPath = XPath.newInstance(xPathExpression);
    String namespaceURI = scopeElement.getDocument().getRootElement().getNamespaceURI();
    if ((namespaceURI != null) && (!"".equals(namespaceURI))) {
        xPath.addNamespace("xp", namespaceURI);
    }//from w  w  w  .  ja  va 2 s  . co m
    for (Namespace additionalNamespace : (List<Namespace>) scopeElement.getDocument().getRootElement()
            .getAdditionalNamespaces()) {
        xPath.addNamespace(additionalNamespace);
    }

    return xPath.selectNodes(scopeElement);
}

From source file:org.jahia.utils.osgi.parsers.AbstractXmlFileParser.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Attribute> getAttributes(Element scopeElement, String xPathExpression) throws JDOMException {
    List<Attribute> elems = new LinkedList<Attribute>();
    XPath xPath = XPath.newInstance(xPathExpression);
    String namespaceURI = scopeElement.getDocument().getRootElement().getNamespaceURI();
    if ((namespaceURI != null) && (!"".equals(namespaceURI))) {
        xPath.addNamespace("xp", namespaceURI);
    }/*  w w  w. j a  v a  2  s  .co  m*/
    for (Namespace additionalNamespace : (List<Namespace>) scopeElement.getDocument().getRootElement()
            .getAdditionalNamespaces()) {
        xPath.addNamespace(additionalNamespace);
    }
    for (Object obj : xPath.selectNodes(scopeElement)) {
        if (obj instanceof Attribute) {
            elems.add((Attribute) obj);
        }
    }

    return elems;
}

From source file:org.jahia.utils.osgi.parsers.AbstractXmlFileParser.java

License:Open Source License

public List<Object> getNodes(Element scopeElement, String xPathExpression, String defaultPrefix)
        throws JDOMException {
    List<Object> nodes = new LinkedList<Object>();
    XPath xPath = XPath.newInstance(xPathExpression);
    String namespaceURI = scopeElement.getDocument().getRootElement().getNamespaceURI();
    if ((namespaceURI != null) && (!"".equals(namespaceURI))) {
        xPath.addNamespace(defaultPrefix, namespaceURI);
    }/* w  ww  .  jav  a 2  s.  c o m*/
    for (Namespace additionalNamespace : (List<Namespace>) scopeElement.getDocument().getRootElement()
            .getAdditionalNamespaces()) {
        xPath.addNamespace(additionalNamespace);
    }
    for (Object obj : xPath.selectNodes(scopeElement)) {
        nodes.add(obj);
    }
    return nodes;
}

From source file:org.yawlfoundation.yawl.scheduling.util.XMLUtils.java

License:Open Source License

@SuppressWarnings("unchecked")
public static List getXMLObjects(Document doc, String xpath) {
    List objects = new ArrayList();
    try {/*from  ww w .  j a  v  a2  s  .  c o  m*/
        XPath xp = XPath.newInstance(xpath);
        objects = xp.selectNodes(doc);
    } catch (Exception e) {
        logger.error("cannot process xpath: " + xpath + " on document: "
                + Utils.element2String(doc == null ? null : doc.getRootElement(), true));
    }
    return objects;
}