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

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

本文整理了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

  1. private Map<String, String> readInitParams(Node configData) {
  2. Map<String, String> paramMap = new HashMap<>();
  3. List<Node> params = configData.selectNodes("init-params/init-param");
  4. for (Node param : params) {
  5. String paramName = param.selectSingleNode("param-name").getStringValue();
  6. String paramValue = param.selectSingleNode("param-value").getStringValue();
  7. paramMap.put(paramName, paramValue);
  8. }
  9. return paramMap;
  10. }

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

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

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

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

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

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

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

  1. @Nullable
  2. private Node getErrorMessageNode(@NotNull Node testNode, @NotNull String namespacePrefix)
  3. {
  4. if (namespacePrefix.equals(VS_2006_PREFIX))
  5. {
  6. return testNode.selectSingleNode(namespacePrefix + "Output");
  7. }
  8. else
  9. {
  10. return testNode.selectSingleNode(namespacePrefix + "Output/" + namespacePrefix + "ErrorInfo/" + namespacePrefix + "Message");
  11. }
  12. }

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

  1. SAXReader reader = new SAXReader();
  2. Document document = reader.read(file);
  3. List<Node> nodes = document.selectNodes("/options/category/option");
  4. for (Node node : nodes) {
  5. System.out.println("caption: " + node.selectSingleNode("control/caption").getText());
  6. System.out.println("value : " + node.selectSingleNode("value").getText());
  7. }

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

  1. public int compare(Object o1, Object o2) {
  2. try {
  3. Double pos1 = Double.parseDouble(((Node) o1).selectSingleNode("Position").getText());
  4. Double pos2 = Double.parseDouble(((Node) o2).selectSingleNode("Position").getText());
  5. return pos1.compareTo(pos2);
  6. } catch (Exception e) {
  7. return 0;
  8. }
  9. }
  10. }

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

  1. public int compare(Object o1, Object o2) {
  2. try {
  3. Double pos1 = Double.parseDouble(((Node) o1).selectSingleNode("Sort").getText());
  4. Double pos2 = Double.parseDouble(((Node) o2).selectSingleNode("Sort").getText());
  5. return pos1.compareTo(pos2);
  6. } catch (Exception e) {
  7. return 0;
  8. }
  9. }
  10. }

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

  1. public static String getNodeText( final String xpath, final Node rootNode, final String defaultValue ) {
  2. if ( rootNode == null ) {
  3. return ( defaultValue );
  4. }
  5. Node node = rootNode.selectSingleNode( xpath );
  6. if ( node == null ) {
  7. return defaultValue;
  8. }
  9. return node.getText();
  10. }

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

  1. public Map<String, String> getDefaultClassesConfigForKey(String key) throws DocumentException, IOException
  2. {
  3. Map<String, String> defaults = new HashMap<>();
  4. for (Node node : defaultsBaseNodes)
  5. {
  6. Node defaultsNode = node.selectSingleNode(key);
  7. if (defaultsNode != null)
  8. defaults.putAll(XMLConfigUtil.parseRepositoryElementForClassNames((Element) defaultsNode));
  9. }
  10. return defaults;
  11. }

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

  1. /**
  2. * Executes the specified XPath query as a single node query, returning the text value of the resulting single node.
  3. */
  4. public static String selectSingleNodeValue(Node node, String xpathQuery) {
  5. Node resultNode = node.selectSingleNode(xpathQuery);
  6. if (resultNode != null) {
  7. return resultNode.getText();
  8. } else {
  9. return null;
  10. }
  11. }

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

  1. private Map<String, String> readInitParams(Node configData) {
  2. Map<String, String> paramMap = new HashMap<>();
  3. List<Node> params = configData.selectNodes("init-params/init-param");
  4. for (Node param : params) {
  5. String paramName = param.selectSingleNode("param-name").getStringValue();
  6. String paramValue = param.selectSingleNode("param-value").getStringValue();
  7. paramMap.put(paramName, paramValue);
  8. }
  9. return paramMap;
  10. }

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

  1. private Optional<Duration> parseDuration(@NotNull Node testNode)
  2. {
  3. // duration will be in hh:mm:ss.mmmmmmm format
  4. final Node durationAttr = testNode.selectSingleNode("@duration");
  5. if (durationAttr != null)
  6. {
  7. return convertDuration(durationAttr.getStringValue());
  8. }
  9. return Optional.empty();
  10. }

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

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

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

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

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

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

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

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

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

  1. @Override
  2. public String apply(Tuple<String, Node> data) {
  3. final String[] keyParts = splitKey(data.first);
  4. final Node node =
  5. data.second.selectSingleNode(
  6. "/permission-set/principal/child::node()/child::text()");
  7. final String principal = node.getText();
  8. return principal + "__" + keyParts[3] + "__" + keyParts[0];
  9. }
  10. }

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

  1. protected Object getInputValue( final String inputName ) {
  2. // first check to see if we have an input parameter that we can use for
  3. // this.
  4. if ( runtimeContext.getInputNames().contains( inputName ) ) {
  5. return runtimeContext.getInputParameterValue( inputName );
  6. }
  7. // now check the component node from the action definition.
  8. Node node = componentDefinition.selectSingleNode( inputName );
  9. if ( node == null ) {
  10. return null;
  11. }
  12. return node.getText();
  13. }

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

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

相关文章