带有 namespace的xpath的创建

public static XPath createXPath(Element e,String xpath,String namespacePrefix){
    	XPath x=e.createXPath(xpath);
    	Namespace namespace=e.getNamespace();
    	String prefix = null;
    	//此 Element 不包含namespace
    	if(namespace.getURI()!=null&&"".equals(namespace.getURI())){
    		return x;
    	}
    	
    	if(namespacePrefix!=null){
    		prefix = namespacePrefix;
    	}else{
    		prefix = namespace.getPrefix();
    	}
    	Map map = new HashMap();
    	//添加命名空间
		map.put(prefix,namespace.getURI());
		x.setNamespaceURIs(map);
		return x;
    }

猜你喜欢

转载自my.oschina.net/u/929672/blog/159452