List of usage examples for org.dom4j.xpath DefaultXPath setNamespaceContext
public void setNamespaceContext(NamespaceContext namespaceContext)
From source file:com.surenpi.autotest.suite.parser.XmlSuiteParser.java
License:Apache License
/** * ?action/*from www . j a v a 2 s . co m*/ * @param actionList * @param actionsEle action * @param afterSleep action * @param beforeSleep action */ private void parse(List<SuiteAction> actionList, final Element actionsEle, String beforeSleep, String afterSleep) { DefaultXPath xpath = new DefaultXPath("ns:action"); xpath.setNamespaceContext(simpleNamespaceContext); @SuppressWarnings("unchecked") List<Element> actionEleList = xpath.selectNodes(actionsEle); for (Element actionEle : actionEleList) { String field = actionEle.attributeValue("field"); String name = actionEle.attributeValue("name", "click"); String invoker = actionEle.attributeValue("invoker"); String actionBeforeSleep = actionEle.attributeValue("beforeSleep", beforeSleep); String actionAfterSleep = actionEle.attributeValue("afterSleep", afterSleep); String repeat = actionEle.attributeValue("repeat", "1"); String disable = actionEle.attributeValue("disable", "false"); if (Boolean.parseBoolean(disable)) { continue; } SuiteAction suiteAction = new SuiteAction(field, name); suiteAction.setInvoker(invoker); suiteAction.setBeforeSleep(Long.parseLong(actionBeforeSleep)); suiteAction.setAfterSleep(Long.parseLong(actionAfterSleep)); suiteAction.setRepeat(Integer.parseInt(repeat)); parseActionParam(actionEle, suiteAction); actionList.add(suiteAction); } }
From source file:org.compass.core.xml.dom4j.Dom4jXmlObject.java
License:Apache License
/** * Compiles the given xpath expression using dom4j <code>DefaultXPath</code>. */// w ww. j a v a2 s.co m public XmlXPathExpression compile(String path) { DefaultXPath xpath = new DefaultXPath(path); if (namespaces != null) { xpath.setNamespaceContext(new SimpleNamespaceContext(namespaces)); } return new Dom4jXmlXPathExpression(xpath); }
From source file:org.suren.autotest.web.framework.code.DefaultXmlCodeGenerator.java
License:Apache License
/** * @param document//from w w w .ja v a 2s . com */ 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); } } } }