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


Java XPath.selectSingleNode方法代码示例

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


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

示例1: getTagElement

import org.dom4j.XPath; //导入方法依赖的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

示例2: getElement

import org.dom4j.XPath; //导入方法依赖的package包/类
public Element getElement( String xpathExpr )
    throws XMLException
{
    XPath xpath = createXPath( xpathExpr );
    Object evaluated = xpath.selectSingleNode( document );

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

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

示例3: getElementText

import org.dom4j.XPath; //导入方法依赖的package包/类
public String getElementText( Node context, String xpathExpr )
    throws XMLException
{
    XPath xpath = createXPath( xpathExpr );
    Object evaluated = xpath.selectSingleNode( context );

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

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

示例4: getAttributeValue

import org.dom4j.XPath; //导入方法依赖的package包/类
/**
 * Extracts the value of the supplied attribute
 * 
 * @param element
 *            element with attribute in question
 * @param attributeName
 *            name of the attribute in question
 * @param failIfNotFound
 *            determines if exception should be thrown if attribute is not
 *            found
 * @return value of the attribute in question, null if not found and
 *         failIfNotFound is set to false
 * @throws GenericArtifactParsingException
 *             exception thrown is attribute is missing and failIfNotFound
 *             is set to true
 */
public static String getAttributeValue(Element element,
        String attributeName, boolean failIfNotFound)
        throws GenericArtifactParsingException {
    XPath xpath = new DefaultXPath("@" + attributeName);
    xpath.setNamespaceURIs(ccfNamespaceMap);
    Node attributeNode = xpath.selectSingleNode(element);
    if (attributeNode == null) {
        if (failIfNotFound) {
            throw new GenericArtifactParsingException("Missing attribute: "
                    + attributeName + " in element " + element.getName());
        } else {
            return null;
        }
    } else {
        return attributeNode.getText();
    }
}
 
开发者ID:jonico,项目名称:core,代码行数:34,代码来源:XPathUtils.java

示例5: getCollectionKeyFromDDS

import org.dom4j.XPath; //导入方法依赖的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

示例6: getValue

import org.dom4j.XPath; //导入方法依赖的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

示例7: getValue

import org.dom4j.XPath; //导入方法依赖的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

示例8: InfoXML

import org.dom4j.XPath; //导入方法依赖的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

示例9: parse

import org.dom4j.XPath; //导入方法依赖的package包/类
/**
	 * 解析测试套件配置文件
	 * @param suiteInputStream 配置文件输入流
	 * @return 测试套件对象
	 * @throws DocumentException
	 */
	public Suite parse(InputStream suiteInputStream) throws DocumentException
	{
		SAXReader reader = new SAXReader();
		reader.setEncoding("utf-8");
		
		Document document = reader.read(suiteInputStream);
		
		simpleNamespaceContext.addNamespace("ns", NS_URI);
		
		XPath xpath = new DefaultXPath("/ns:suite");
		xpath.setNamespaceContext(simpleNamespaceContext);
		Element suiteEle = (Element) xpath.selectSingleNode(document);
		if (suiteEle == null)
		{
			suiteEle = document.getRootElement();
//			throw new RuntimeException("Can not found suite config.");
		}
		
		Suite suite = new Suite();
		String xmlConfPath = suiteEle.attributeValue("pageConfig");
		String pagePackage = suiteEle.attributeValue("pagePackage", "");
		String rows = suiteEle.attributeValue("rows", "1");
		String lackLines = suiteEle.attributeValue("lackLines", "nearby");
		String errorLines = suiteEle.attributeValue("errorLines", "stop");
		String afterSleep = suiteEle.attributeValue("afterSleep", "0");
		
		suite.setXmlConfPath(xmlConfPath);
		suite.setPagePackage(pagePackage);
		suite.setRows(rows);
		suite.setLackLines(lackLines);
		suite.setErrorLines(errorLines);
		suite.setAfterSleep(Long.parseLong(afterSleep));
		
		pagesParse(document, suite);
		
		return suite;
	}
 
开发者ID:LinuxSuRen,项目名称:phoenix.webui.suite.runner,代码行数:44,代码来源:XmlSuiteParser.java

示例10: hasElement

import org.dom4j.XPath; //导入方法依赖的package包/类
public boolean hasElement( String xpathExpr )
    throws XMLException
{
    XPath xpath = createXPath( xpathExpr );
    Object evaluated = xpath.selectSingleNode( document );

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

    return true;
}
 
开发者ID:ruikom,项目名称:apache-archiva,代码行数:14,代码来源:XMLReader.java

示例11: getAttributeValue

import org.dom4j.XPath; //导入方法依赖的package包/类
/**
 * Extracts the value of the supplied attribute
 * 
 * @param element
 *            element with attribute in question
 * @param attributeName
 *            name of the attribute in question
 * @return value of the attribute in question
 * @throws GenericArtifactParsingException
 *             exception s thrown is attribute is missing
 */
private static String getAttributeValue(Element element,
        String attributeName) throws GenericArtifactParsingException {
    // TODO Cash constructed XPath objects?
    // XPath xpath = new DefaultXPath("@" + CCF_NAMESPACE_PREFIX + ":" +
    // attributeName);
    XPath xpath = new DefaultXPath("@" + attributeName);
    xpath.setNamespaceURIs(ccfNamespaceMap);
    Node attributeNode = xpath.selectSingleNode(element);
    if (attributeNode == null)
        throw new GenericArtifactParsingException("Missing attribute: "
                + attributeName + " in element " + element.getName());
    else
        return attributeNode.getText();
}
 
开发者ID:jonico,项目名称:core,代码行数:26,代码来源:GenericArtifactHelper.java

示例12: getAttributeValueWithoutException

import org.dom4j.XPath; //导入方法依赖的package包/类
/**
 * Extracts the value of the supplied attribute without throwing an
 * exception if missing
 * 
 * @param element
 *            element with attribute in question
 * @param attributeName
 *            name of the attribute in question
 * @return value of the attribute in question, null if attribute is missing
 * 
 */
private static String getAttributeValueWithoutException(Element element,
        String attributeName) {
    // TODO Cash constructed XPath objects?
    // XPath xpath = new DefaultXPath("@" + CCF_NAMESPACE_PREFIX + ":" +
    // attributeName);
    XPath xpath = new DefaultXPath("@" + attributeName);
    xpath.setNamespaceURIs(ccfNamespaceMap);
    Node attributeNode = xpath.selectSingleNode(element);
    if (attributeNode == null)
        return null;
    else
        return attributeNode.getText();
}
 
开发者ID:jonico,项目名称:core,代码行数:25,代码来源:GenericArtifactHelper.java

示例13: extractBoxConstraint

import org.dom4j.XPath; //导入方法依赖的package包/类
private int[] extractBoxConstraint(Element root) {
  int[] result = new int[4];
  String nodeName = currentToken.getNode().getName();
  XPath xPath = new DefaultXPath("//node[@name='" + nodeName + "']");
  Element node = (Element) xPath.selectSingleNode(root);
  result[0] = Integer.valueOf(node.attribute("x").getValue()).intValue();
  result[1] = Integer.valueOf(node.attribute("y").getValue()).intValue();
  result[2] = Integer.valueOf(node.attribute("width").getValue()).intValue();
  result[3] = Integer.valueOf(node.attribute("height").getValue()).intValue();
  return result;
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:12,代码来源:JBPMProcessImageTag.java

示例14: render

import org.dom4j.XPath; //导入方法依赖的package包/类
public void render(final InputStream in, final OutputStream out, final Map<String , String> config)
    throws Exception {
	SAXReader reader = new SAXReader();
    Document document = reader.read(in);
    
    XPath xpath = new DefaultXPath("/l:LexML/l:Metadado/l:Identificacao");
    Map<String,String> ns = new HashMap<String,String>();
    ns.put("l","http://www.lexml.gov.br/1.0");
    xpath.setNamespaceURIs(ns);        
    Node n = xpath.selectSingleNode(document);
    //System.out.println("n:" + n);
    //System.out.println("attributes: " + ((Element) n).attributes());
    String urn = ((Element)n).attributeValue("URN");
    //System.out.println("urn:" + urn);
    String[] urnComps = urn.split(":");
    String autoridade = urnComps[3];
    String tipoNorma = urnComps[4];
                	    	    	
    RendererPDFContext ctx = new RendererPDFContext(autoridade,tipoNorma);
    ctx.addConfig(config);
    
    Element root = document.getRootElement();

    ctx.setOutputStream(out);

    new PDFBuilder(ctx, root).build();

}
 
开发者ID:lexml,项目名称:lexml-renderer-pdf,代码行数:29,代码来源:RendererPDF.java

示例15: loadCollection

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