Example usage for org.dom4j.xpath DefaultXPath selectSingleNode

List of usage examples for org.dom4j.xpath DefaultXPath selectSingleNode

Introduction

In this page you can find the example usage for org.dom4j.xpath DefaultXPath selectSingleNode.

Prototype

public Node selectSingleNode(Object context) 

Source Link

Usage

From source file:de.bbe_consulting.mavento.AbstractArchetypeMojo.java

License:Apache License

protected String getXmlNodeValueFromPom(String xpathNode, Document pom) throws MojoExecutionException {
    DefaultXPath path = new DefaultXPath(xpathNode);
    Map<String, String> namespaces = new TreeMap<String, String>();
    namespaces.put("x", "http://maven.apache.org/POM/4.0.0");

    path.setNamespaceURIs(namespaces);//from  w ww  .j av  a 2 s . c o m
    Node n = path.selectSingleNode(pom.getRootElement());

    return n.getStringValue();
}

From source file:org.suren.autotest.web.framework.code.DefaultXmlCodeGenerator.java

License:Apache License

/**
 * @param document/*from  w w w. jav a2 s  .  c o m*/
 */
private void read(Document doc) {
    SimpleNamespaceContext simpleNamespaceContext = new SimpleNamespaceContext();
    simpleNamespaceContext.addNamespace("ns", "http://surenpi.com");

    DefaultXPath xpath = new DefaultXPath("/ns:autotest/ns:pages");
    xpath.setNamespaceContext(simpleNamespaceContext);
    Element pagesEle = (Element) xpath.selectSingleNode(doc);
    String pagePackage = pagesEle.attributeValue("pagePackage", "");
    if (StringUtils.isNotBlank(pagePackage)) {
        pagePackage = (pagePackage.trim() + ".");
    }

    // pages parse progress
    xpath = new DefaultXPath("/ns:autotest/ns:pages/ns:page");
    xpath.setNamespaceContext(simpleNamespaceContext);
    @SuppressWarnings("unchecked")
    List<Element> pageNodes = xpath.selectNodes(doc);
    if (pageNodes != null) {
        for (Element ele : pageNodes) {
            String pageClsStr = ele.attributeValue("class");
            if (pageClsStr == null) {
                logger.warn("can not found class attribute.");
                continue;
            }

            pageClsStr = (pagePackage + pageClsStr);
            Object commentObj = ele.getData();
            if (commentObj != null) {
                pageCommentMap.put(pageClsStr, commentObj.toString().trim());
            }

            try {
                List<AutoField> fieldList = new ArrayList<AutoField>();

                pageFieldMap.put(pageClsStr, fieldList);

                parsePage(pageClsStr, ele, fieldList);
            } catch (Exception e) {
                logger.error("page element parse error.", e);
            }
        }
    }
}