当前位置: 首页>>代码示例>>Java>>正文


Java XPath.evaluate方法代码示例

本文整理汇总了Java中org.dom4j.XPath.evaluate方法的典型用法代码示例。如果您正苦于以下问题:Java XPath.evaluate方法的具体用法?Java XPath.evaluate怎么用?Java XPath.evaluate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.dom4j.XPath的用法示例。


在下文中一共展示了XPath.evaluate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getElementList

import org.dom4j.XPath; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public List<Element> getElementList( String xpathExpr )
    throws XMLException
{
    XPath xpath = createXPath( xpathExpr );
    Object evaluated = xpath.evaluate( document );

    if ( evaluated == null )
    {
        return null;
    }

    /* The xpath.evaluate(Context) method can return:
     *   1) A Collection or List of dom4j Nodes. 
     *   2) A single dom4j Node.
     */

    if ( evaluated instanceof List )
    {
        return (List<Element>) evaluated;
    }
    else if ( evaluated instanceof Node )
    {
        List<Element> ret = new ArrayList<>();
        ret.add( (Element) evaluated );
        return ret;
    }
    else
    {
        // Unknown evaluated type.
        throw new XMLException( ".getElementList( Expr: " + xpathExpr + " ) resulted in non-List type -> ("
                                    + evaluated.getClass().getName() + ") " + evaluated );
    }
}
 
开发者ID:ruikom,项目名称:apache-archiva,代码行数:35,代码来源:XMLReader.java

示例2: flat

import org.dom4j.XPath; //导入方法依赖的package包/类
/**
 * Document to Flat
 */
public void flat() {
	XPath loopXpath = null;
	if(!defineNS) {
		loopXpath = doc.createXPath(namespaceTool.addDefaultNSPrefix(currentLoop, currentLoop));
	} else {
		loopXpath = doc.createXPath(currentLoop);
	}
	loopXpath.setNamespaceURIs(xmlNameSpaceMap);
	nodes = loopXpath.selectNodes(doc);
	if(this.isOptional && nodes.size() == 0 && !top) {
		setParentAsLoop();
		flat();
	} else if (nodes !=null ) {
		//reset relative paths
		if(currentLoop != originalLoop) {//not point to the same string
			for(int i=0;i<currentRelativePathMappings.length;i++) {
				currentRelativePathMappings[i] = resetRelativeXPath(currentRelativePathMappings[i]);
			}
		}
		
		for(AbstractNode node : nodes) {
			//init row
			Map<String,String> row = new HashMap<String,String>();
			resultSet.add(row);
			//init columns for one row
			for(int i=0;i<currentRelativePathMappings.length;i++) {
				String relativePath = currentRelativePathMappings[i];
				XPath xpath = null;
				if(!defineNS) {
					xpath = node.createXPath(namespaceTool.addDefaultNSPrefix(relativePath, currentLoop));
				} else {
					xpath = node.createXPath(relativePath);
				}
				xpath.setNamespaceURIs(xmlNameSpaceMap);
				Object obj = xpath.evaluate(node);
				if(obj instanceof String || obj instanceof Number){
					row.put(absolutePathMappings[i], String.valueOf(obj));
		    	}else{
			    	row.put(absolutePathMappings[i], xpath.selectSingleNode(node)!=null ? xpath.valueOf(node) : null);
			    }
			}
		}
		doc = null;
		nodes = null;
	}
}
 
开发者ID:bio2rdf,项目名称:bio2rdf-rest,代码行数:50,代码来源:DocumentToFlat.java


注:本文中的org.dom4j.XPath.evaluate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。