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


Java DocumentHelper.createXPath方法代码示例

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


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

示例1: getRecordCount

import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
public int getRecordCount () 
{				
    Map<String,String> uris = new HashMap<String,String>();
    uris.put( "ddsws", "http://www.dlese.org/Metadata/ddsws" );
    uris.put( "groups", "http://www.dlese.org/Metadata/groups/" );
    uris.put( "adn", "http://adn.dlese.org" );
    uris.put( "annotation", "http://www.dlese.org/Metadata/annotation" );
    
    XPath xpath = DocumentHelper.createXPath( "//ddsws:results/ddsws:record" );

    xpath.setNamespaceURIs( uris );
    
	List recordNodes = xpath.selectNodes(this.document);
    
    return recordNodes.size();		
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:17,代码来源:CollectionImporter.java

示例2: getTagElement

import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
private Element getTagElement (String _tag, String _namespacePrefix, String _namespaceURI ) {
	
	Element tagElement = null; // caller is responsible for handling null
	
	try {
		// TODO  this isn't complete, as we can have any arbitrary tag and values for them infinitely deep
		XPath xpath = DocumentHelper.createXPath( "//" + ( _namespacePrefix != null ? _namespacePrefix + ":" : "" ) + _tag.trim() );
		SimpleNamespaceContext ns = new SimpleNamespaceContext();
		ns.addNamespace( _namespacePrefix, _namespaceURI );  
		xpath.setNamespaceContext(ns);

		tagElement = ((Element)xpath.selectSingleNode(this.infoxmlDoc));
		
	}  catch ( Exception e ) {
		e.printStackTrace();
	}
	
	return tagElement;		
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:20,代码来源:InfoXML.java

示例3: getCollectionKeyFromDDS

import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
public String getCollectionKeyFromDDS( String _collectionName )
{
	String collectionKey = null;

	// make the call to DDS and get ListCollections 
	try { 
		URLConnection connection = new URL ("http://www.dlese.org/dds/services/ddsws1-1?verb=ListCollections" ).openConnection();			
        connection.setDoOutput( true );
        connection.setDoInput(true);
        
        ((HttpURLConnection)connection).setRequestMethod("GET");
        
        Map<String,String> uris = new HashMap<String,String>();
	    uris.put( "ddsws", "http://www.dlese.org/Metadata/ddsws" );	       
        uris.put( "ddswsnews", "http://www.dlese.org/Metadata/ddswsnews" );
	    uris.put( "groups", "http://www.dlese.org/Metadata/groups/" );
	    uris.put( "adn", "http://adn.dlese.org" );
	    uris.put( "annotation", "http://www.dlese.org/Metadata/annotation" );
	    
	    XPath xpath = DocumentHelper.createXPath( "//collections/collection[vocabEntry=\"" + _collectionName + "\"]/searchKey/text()" );

	    xpath.setNamespaceURIs( uris );
	    
	    SAXReader xmlReader = new SAXReader();
	    
	    this.document = xmlReader.read(connection.getInputStream());	
	            
	    Text t = ((Text)xpath.selectSingleNode(this.document));
	    
		collectionKey = t.getStringValue();
		
	} catch ( Exception e ) {
		e.printStackTrace();
	}
	
	return collectionKey;
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:38,代码来源:CollectionImporter.java

示例4: getValue

import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
private String getValue(String xpath) {
	XPath xpathObj = DocumentHelper.createXPath(xpath);
	xpathObj.setNamespaceURIs(getNSMap());
	Node node = xpathObj.selectSingleNode(doc);
	if (node != null)
		return node.getText();
	else
		return null;
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:10,代码来源:ServiceDescriptionReader.java

示例5: getValue

import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
private String getValue (String xpath) {
	XPath xpathObj = DocumentHelper.createXPath(xpath);
	xpathObj.setNamespaceURIs(getNSMap());
	Node node = xpathObj.selectSingleNode(doc);
	if (node != null)
		return node.getText();
	else
		return null;
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:10,代码来源:NsdlDcReader.java

示例6: getValues

import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
private List getValues(String xpath) {
	XPath xpathObj = DocumentHelper.createXPath(xpath);
	xpathObj.setNamespaceURIs(getNSMap());
	List nodes = xpathObj.selectNodes(doc);
	List values = new ArrayList();
	for (Iterator i = nodes.iterator(); i.hasNext(); ) {
		values.add(((Node) i.next()).getText());
	}
	return values;
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:11,代码来源:HarvestInfoReader.java

示例7: InfoXML

import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
/**
 * Constructs the infoXML abstraction based on the input
 * given.
 * 
 * @param _xml
 */
public InfoXML ( String _xml )
{
	try {
		// TODO : BARFS on the xsi: attribute on return saying :
		//			org.dom4j.DocumentException: Error on line 1 of document  : 
		//			The prefix "xsi" for attribute "xsi:schemaLocation" associated with 
		//			an element type "NSDLDataRepository" is not bound. 
		//			Nested exception: The prefix "xsi" for attribute "xsi:schemaLocation" 
		//			associated with an element type "NSDLDataRepository" is not bound.

		this.contentRaw = _xml;
		this.infoxmlDoc = DocumentHelper.parseText( this.contentRaw );
					
		XPath xpath = DocumentHelper.createXPath( "//ndr:error" ); // for error node checks

		// TODO : though the default namespace is NOT called NDR,
		// http://www.xslt.com/html/xsl-list/2005-03/msg01059.html indicates we must give
		// it one if we are to use it in an XPath.  How fun is that!
		SimpleNamespaceContext ns = new SimpleNamespaceContext();
		ns.addNamespace("ndr", "http://ns.nsdl.org/ndr/response_v1.00/");
		
		xpath.setNamespaceContext(ns);
		
		// select the error node
    	Element error = (Element)xpath.selectSingleNode(this.infoxmlDoc);
    	
    	if ( error != null )
    	{
    		this.hasErrors = true;
    		this.errorString = error.getText();
    	}
    	
	} catch ( Exception e ) {
		this.contentRaw = _xml;
		this.errorString = "Fatal error in InfoXML construction.";
		// e.printStackTrace();
	}		
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:45,代码来源:InfoXML.java

示例8: loadCollection

import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
public void loadCollection()
{
	if ( metaObjects == null ) {
	    metaObjects = new HashMap<String, ArrayList<String>>();  
		
		Map<String,String> uris = new HashMap<String,String>();
	    uris.put( "ddsws", "http://www.dlese.org/Metadata/ddsws" );
	    uris.put( "groups", "http://www.dlese.org/Metadata/groups/" );
	    uris.put( "adn", "http://adn.dlese.org" );
	    uris.put( "annotation", "http://www.dlese.org/Metadata/annotation" );
	    
	    XPath xpath = DocumentHelper.createXPath( "//ddsws:results/ddsws:record" );

	    xpath.setNamespaceURIs( uris );
	    
		List recordNodes = xpath.selectNodes(this.document);
	    
	    for ( Iterator iter = recordNodes.iterator(); iter.hasNext(); ) 
	    {
	        Element element = (Element) iter.next();
	        
	        XPath meta = DocumentHelper.createXPath( "./ddsws:metadata" ); 
	        XPath resURL = DocumentHelper.createXPath( "./ddsws:metadata/adn:itemRecord/adn:technical/adn:online/adn:primaryURL" );
	        XPath resId = DocumentHelper.createXPath("./ddsws:head/ddsws:additionalMetadata/ddsws:adn/ddsws:annotatedBy/ddsws:record/ddsws:head/ddsws:id");//adn:adn/adn:annotatedBy/adn:record/adn:head/adn:id");
	        
	        meta.setNamespaceURIs( uris );
	        resId.setNamespaceURIs( uris );
	        resURL.setNamespaceURIs( uris );
	        
	        Node metadata = meta.selectSingleNode(element);
	        Element resourceId = (Element)resId.selectSingleNode(element);
	        Element resourceURL = (Element)resURL.selectSingleNode(element);
	        
	        if ( resourceId != null && resourceURL != null && metadata != null  )
	        {
	        	// add the resId as the hash key
	        	metaObjects.put(
        			resourceId.getTextTrim(), 
        			new ArrayList<String>(Arrays.asList( resourceURL.getTextTrim(), metadata.asXML() ))
       			);		        		        
	        }		        
	    }
	}		    
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:45,代码来源:CollectionImporter.java


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