org.dom4j.Node.selectSingleNode()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(158)

本文整理了Java中org.dom4j.Node.selectSingleNode()方法的一些代码示例,展示了Node.selectSingleNode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.selectSingleNode()方法的具体详情如下:
包路径:org.dom4j.Node
类名称:Node
方法名:selectSingleNode

Node.selectSingleNode介绍

[英]selectSingleNode evaluates an XPath expression and returns the result as a single Node instance.
[中]selectSingleNode对XPath表达式求值,并将结果作为单个Node实例返回。

代码示例

代码示例来源:origin: igniterealtime/Openfire

private Map<String, String> readInitParams(Node configData) {
  Map<String, String> paramMap = new HashMap<>();
  List<Node> params = configData.selectNodes("init-params/init-param");
  for (Node param : params) {
    String paramName = param.selectSingleNode("param-name").getStringValue();
    String paramValue = param.selectSingleNode("param-value").getStringValue();
    paramMap.put(paramName, paramValue);
  }
  return paramMap;
}

代码示例来源:origin: spotbugs/spotbugs

private static String getChildText(Node node, String childName) throws PluginException {
  Node child = node.selectSingleNode(childName);
  if (child == null) {
    throw new PluginException("Could not find child \"" + childName + "\" for node");
  }
  return child.getText();
}

代码示例来源:origin: igniterealtime/Openfire

private void registerCache(String pluginName, Node configData) {
  String cacheName = configData.selectSingleNode("cache-name").getStringValue();
  String schemeName = configData.selectSingleNode("scheme-name").getStringValue();
  if (cacheName == null || schemeName == null) {
    throw new IllegalArgumentException("Both cache-name and scheme-name elements are required. Found cache-name: " + cacheName +
    " and scheme-name: " + schemeName);
  }
  Map<String, String> initParams = readInitParams(configData);
  CacheInfo info = new CacheInfo(cacheName, CacheInfo.Type.valueof(schemeName), initParams);
  PluginCacheRegistry.getInstance().registerCache(pluginName, info);
}

代码示例来源:origin: pentaho/pentaho-kettle

} else {
 Node n = node.selectSingleNode( XPathValue );
 if ( n != null ) {
  nodevalue = n.asXML();

代码示例来源:origin: com.atlassian.bamboo.plugins.dotnet/atlassian-bamboo-plugin-dotnet

@Nullable
private Node getErrorMessageNode(@NotNull Node testNode, @NotNull String namespacePrefix)
{
  if (namespacePrefix.equals(VS_2006_PREFIX))
  {
    return testNode.selectSingleNode(namespacePrefix + "Output");
  }
  else
  {
    return testNode.selectSingleNode(namespacePrefix + "Output/" + namespacePrefix + "ErrorInfo/" + namespacePrefix + "Message");
  }
}

代码示例来源:origin: stackoverflow.com

SAXReader reader = new SAXReader();
Document document = reader.read(file);
List<Node> nodes = document.selectNodes("/options/category/option");

for (Node node : nodes) {
  System.out.println("caption: " + node.selectSingleNode("control/caption").getText());
  System.out.println("value : " + node.selectSingleNode("value").getText());
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.quickfix

public int compare(Object o1, Object o2) {
    try {
      Double pos1 = Double.parseDouble(((Node) o1).selectSingleNode("Position").getText());
      Double pos2 = Double.parseDouble(((Node) o2).selectSingleNode("Position").getText());
      return pos1.compareTo(pos2);
    } catch (Exception e) {
      return 0;
    }
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.quickfix

public int compare(Object o1, Object o2) {
    try {
      Double pos1 = Double.parseDouble(((Node) o1).selectSingleNode("Sort").getText());
      Double pos2 = Double.parseDouble(((Node) o2).selectSingleNode("Sort").getText());
      return pos1.compareTo(pos2);
    } catch (Exception e) {
      return 0;
    }
  }
}

代码示例来源:origin: pentaho/pentaho-platform

public static String getNodeText( final String xpath, final Node rootNode, final String defaultValue ) {
 if ( rootNode == null ) {
  return ( defaultValue );
 }
 Node node = rootNode.selectSingleNode( xpath );
 if ( node == null ) {
  return defaultValue;
 }
 return node.getText();
}

代码示例来源:origin: com.atlassian.user/atlassian-user-core

public Map<String, String> getDefaultClassesConfigForKey(String key) throws DocumentException, IOException
{
  Map<String, String> defaults = new HashMap<>();
  for (Node node : defaultsBaseNodes)
  {
    Node defaultsNode = node.selectSingleNode(key);
    if (defaultsNode != null)
      defaults.putAll(XMLConfigUtil.parseRepositoryElementForClassNames((Element) defaultsNode));
  }
  return defaults;
}

代码示例来源:origin: org.craftercms/crafter-core

/**
 * Executes the specified XPath query as a single node query, returning the text value of the resulting single node.
 */
public static String selectSingleNodeValue(Node node, String xpathQuery) {
  Node resultNode = node.selectSingleNode(xpathQuery);
  if (resultNode != null) {
    return resultNode.getText();
  } else {
    return null;
  }
}

代码示例来源:origin: org.igniterealtime.openfire/xmppserver

private Map<String, String> readInitParams(Node configData) {
  Map<String, String> paramMap = new HashMap<>();
  List<Node> params = configData.selectNodes("init-params/init-param");
  for (Node param : params) {
    String paramName = param.selectSingleNode("param-name").getStringValue();
    String paramValue = param.selectSingleNode("param-value").getStringValue();
    paramMap.put(paramName, paramValue);
  }
  return paramMap;
}

代码示例来源:origin: com.atlassian.bamboo.plugins.dotnet/atlassian-bamboo-plugin-dotnet

private Optional<Duration> parseDuration(@NotNull Node testNode)
{
  // duration will be in hh:mm:ss.mmmmmmm format
  final Node durationAttr = testNode.selectSingleNode("@duration");
  if (durationAttr != null)
  {
    return convertDuration(durationAttr.getStringValue());
  }
  return Optional.empty();
}

代码示例来源:origin: quickfix-j/quickfixj

private String getSingleNodeTextSafe(Node node, String tag) {
  Node nodeWithTag = node.selectSingleNode(tag);
  if(nodeWithTag != null)
    return nodeWithTag.getText();
  else
    throw new RuntimeException("Node with tag "+tag+" not found in "+node.getPath());
}

代码示例来源:origin: org.quickfixj/quickfixj-all

private String getSingleNodeTextSafe(Node node, String tag) {
  Node nodeWithTag = node.selectSingleNode(tag);
  if(nodeWithTag != null)
    return nodeWithTag.getText();
  else
    throw new RuntimeException("Node with tag "+tag+" not found in "+node.getPath());
}

代码示例来源:origin: org.quickfixj/quickfixj-dictgenerator

private String getSingleNodeTextSafe(Node node, String tag) {
  Node nodeWithTag = node.selectSingleNode(tag);
  if(nodeWithTag != null)
    return nodeWithTag.getText();
  else
    throw new RuntimeException("Node with tag "+tag+" not found in "+node.getPath());
}

代码示例来源:origin: com.google.code.findbugs/findbugs

private static String getChildText(Node node, String childName) throws PluginException {
  Node child = node.selectSingleNode(childName);
  if (child == null) {
    throw new PluginException("Could not find child \"" + childName + "\" for node");
  }
  return child.getText();
}

代码示例来源:origin: org.jasig.portal/uPortal-io-types

@Override
  public String apply(Tuple<String, Node> data) {
    final String[] keyParts = splitKey(data.first);

    final Node node =
        data.second.selectSingleNode(
            "/permission-set/principal/child::node()/child::text()");
    final String principal = node.getText();
    return principal + "__" + keyParts[3] + "__" + keyParts[0];
  }
}

代码示例来源:origin: pentaho/pentaho-platform

protected Object getInputValue( final String inputName ) {
 // first check to see if we have an input parameter that we can use for
 // this.
 if ( runtimeContext.getInputNames().contains( inputName ) ) {
  return runtimeContext.getInputParameterValue( inputName );
 }
 // now check the component node from the action definition.
 Node node = componentDefinition.selectSingleNode( inputName );
 if ( node == null ) {
  return null;
 }
 return node.getText();
}

代码示例来源:origin: org.igniterealtime.openfire/xmppserver

private void registerCache(String pluginName, Node configData) {
  String cacheName = configData.selectSingleNode("cache-name").getStringValue();
  String schemeName = configData.selectSingleNode("scheme-name").getStringValue();
  if (cacheName == null || schemeName == null) {
    throw new IllegalArgumentException("Both cache-name and scheme-name elements are required. Found cache-name: " + cacheName +
    " and scheme-name: " + schemeName);
  }
  Map<String, String> initParams = readInitParams(configData);
  CacheInfo info = new CacheInfo(cacheName, CacheInfo.Type.valueof(schemeName), initParams);
  PluginCacheRegistry.getInstance().registerCache(pluginName, info);
}

相关文章