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

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

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

Node.valueOf介绍

[英]valueOf evaluates an XPath expression and returns the textual representation of the results the XPath string-value of this node. The string-value for a given node type is defined in the XPath specification.
[中]valueOf对XPath表达式求值,并将结果的文本表示形式返回到此节点的XPath字符串值。给定节点类型的字符串值在XPath specification中定义。

代码示例

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

  1. Node node = constraintElement.selectSingleNode("./" + singleDetectorElementName);
  2. if (node != null) {
  3. String detectorClass = node.valueOf("@class");
  4. return new SingleDetectorFactorySelector(plugin, detectorClass);
  5. boolean spanPlugins = Boolean.valueOf(node.valueOf("@spanplugins")).booleanValue();
  6. String categoryName = node.valueOf("@name");
  7. if (!"".equals(categoryName)) {
  8. if ("reporting".equals(categoryName)) {
  9. boolean spanPlugins = Boolean.valueOf(node.valueOf("@spanplugins")).booleanValue();
  10. String superName = node.valueOf("@super");
  11. if (!"".equals(superName)) {
  12. try {

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void withoutItemsEnumBindTarget() throws Exception {
  3. BeanWithEnum testBean = new BeanWithEnum();
  4. testBean.setTestEnum(TestEnum.VALUE_2);
  5. getPageContext().getRequest().setAttribute("testBean", testBean);
  6. this.tag.setPath("testEnum");
  7. int result = this.tag.doStartTag();
  8. assertEquals(Tag.SKIP_BODY, result);
  9. String output = "<div>" + getOutput() + "</div>";
  10. SAXReader reader = new SAXReader();
  11. Document document = reader.read(new StringReader(output));
  12. Element rootElement = document.getRootElement();
  13. assertEquals(2, rootElement.elements().size());
  14. Node value1 = rootElement.selectSingleNode("//input[@value = 'VALUE_1']");
  15. Node value2 = rootElement.selectSingleNode("//input[@value = 'VALUE_2']");
  16. assertEquals("TestEnum: VALUE_1",
  17. rootElement.selectSingleNode("//label[@for = '" + value1.valueOf("@id") + "']").getText());
  18. assertEquals("TestEnum: VALUE_2",
  19. rootElement.selectSingleNode("//label[@for = '" + value2.valueOf("@id") + "']").getText());
  20. assertEquals(value2, rootElement.selectSingleNode("//input[@checked]"));
  21. }

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

  1. List<Node> componentNodeList = XMLUtil.selectNodes(pluginDescriptor, "/FindbugsPlugin/PluginComponent");
  2. for (Node componentNode : componentNodeList) {
  3. @DottedClassName String componentKindname = componentNode.valueOf("@componentKind");
  4. if (componentKindname == null) {
  5. throw new PluginException("Missing @componentKind for " + plugin.getPluginId()
  6. + " loaded from " + loadedFrom);
  7. @DottedClassName String componentClassname = componentNode.valueOf("@componentClass");
  8. if (componentClassname == null) {
  9. throw new PluginException("Missing @componentClassname for " + plugin.getPluginId()
  10. + " loaded from " + loadedFrom);
  11. String componentId = componentNode.valueOf("@id");
  12. if (componentId == null) {
  13. throw new PluginException("Missing @id for " + plugin.getPluginId()
  14. String propertiesLocation = componentNode.valueOf("@properties");
  15. boolean disabled = Boolean.valueOf(componentNode.valueOf("@disabled"));
  16. String key = node.valueOf("@key");
  17. String value = node.getText();
  18. properties.setProperty(key, value);
  19. List<Node> findBugsMainList = XMLUtil.selectNodes(pluginDescriptor, "/FindbugsPlugin/FindBugsMain");
  20. for (Node main : findBugsMainList) {
  21. String className = main.valueOf("@class");
  22. if (className == null) {
  23. throw new PluginException("Missing @class for FindBugsMain in plugin" + plugin.getPluginId()
  24. + " loaded from " + loadedFrom);

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void withoutItemsEnumBindTargetWithExplicitLabelsAndValues() throws Exception {
  3. BeanWithEnum testBean = new BeanWithEnum();
  4. testBean.setTestEnum(TestEnum.VALUE_2);
  5. getPageContext().getRequest().setAttribute("testBean", testBean);
  6. this.tag.setPath("testEnum");
  7. this.tag.setItemLabel("enumLabel");
  8. this.tag.setItemValue("enumValue");
  9. int result = this.tag.doStartTag();
  10. assertEquals(Tag.SKIP_BODY, result);
  11. String output = "<div>" + getOutput() + "</div>";
  12. SAXReader reader = new SAXReader();
  13. Document document = reader.read(new StringReader(output));
  14. Element rootElement = document.getRootElement();
  15. assertEquals(2, rootElement.elements().size());
  16. Node value1 = rootElement.selectSingleNode("//input[@value = 'Value: VALUE_1']");
  17. Node value2 = rootElement.selectSingleNode("//input[@value = 'Value: VALUE_2']");
  18. assertEquals("Label: VALUE_1",
  19. rootElement.selectSingleNode("//label[@for = '" + value1.valueOf("@id") + "']").getText());
  20. assertEquals("Label: VALUE_2",
  21. rootElement.selectSingleNode("//label[@for = '" + value2.valueOf("@id") + "']").getText());
  22. assertEquals(value2, rootElement.selectSingleNode("//input[@checked]"));
  23. }

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

  1. String key = optionNode.valueOf("@key");
  2. String value = optionNode.getText().trim();
  3. constructedPlugin.setMyGlobalOption(key, value);

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

  1. nodevalue = node.valueOf( XPathValue );
  2. } else {

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

  1. for (Node n : fooNodes) {
  2. String a = n.valueOf("@a");
  3. String b = n.valueOf("@b");
  4. String c = n.valueOf("@c");
  5. fooNodes.add(new Foo(a, b, c));
  6. }

代码示例来源:origin: org.appdapter/org.appdapter.lib.core

  1. public static Integer getOptionalIntegerValueAtXPath(Node dom4JDoc, String xpath) throws Throwable {
  2. Integer result = null;
  3. String val = dom4JDoc.valueOf(xpath);
  4. if ((val != null) && (val.length() > 0)) {
  5. result = Integer.parseInt(val);
  6. }
  7. return result;
  8. }

代码示例来源:origin: com.atlassian.jira.plugins/jira-fisheye-plugin

  1. public List<Review> parse(List<Node> reviewNodes, String baseUrl, List<String> p4JobIds) {
  2. final List<Review> reviews = new ArrayList<Review>();
  3. for (final Node n : reviewNodes) {
  4. final String id = n.valueOf("permaId/id");
  5. final String title = n.valueOf("name");
  6. final String description = n.valueOf("description");
  7. final String state = n.valueOf("state");
  8. final String linkedIssue = n.valueOf("jiraIssueKey");
  9. final int metaState = MetaStateResolver.resolve(state);
  10. final ReviewImpl review = new ReviewImpl(id, title, description, state, metaState, baseUrl, p4JobIds, linkedIssue);
  11. if (passesFilter(review)) {
  12. reviews.add(review);
  13. }
  14. }
  15. return reviews;
  16. }

代码示例来源:origin: com.atlassian.jira.plugins/jira-fisheye-plugin

  1. public List<CrucibleProject> parse(FishEyeDocumentHolder docHolder) throws IOException {
  2. Document doc = docHolder.getDoc();
  3. List<CrucibleProject> projects = new ArrayList<CrucibleProject>();
  4. List<Node> rows = doc.selectNodes("/projects/projectData");
  5. for (Node row : rows) {
  6. String key = row.valueOf("key");
  7. String name = row.valueOf("name");
  8. String defaultRepositoryName = row.valueOf("defaultRepositoryName");
  9. int id = Integer.parseInt(row.valueOf("id"));
  10. int permissionSchemeId = Integer.parseInt(row.valueOf("permissionSchemeId"));
  11. boolean allowReviewersToJoin = Boolean.valueOf(row.valueOf("allowReviewersToJoin"));
  12. projects.add(new CrucibleProjectImpl(id, key, name, defaultRepositoryName,
  13. permissionSchemeId, allowReviewersToJoin));
  14. }
  15. return projects;
  16. }

代码示例来源:origin: com.bladejava/blade-kit

  1. public String attrValue(String strXPath) {
  2. Node n = document.selectSingleNode(strXPath);
  3. if (n != null) {
  4. return (n.valueOf("@value"));
  5. } else {
  6. return null;
  7. }
  8. }

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

  1. String xmlFileName = "D:/validation/validator/src/summa/sample.xml";
  2. String xPath = "//Root/Address";
  3. Document document = getDocument( xmlFileName );
  4. List<Node> nodes = document.selectNodes( xPath );
  5. for (Node node : nodes)
  6. {
  7. String studentId = node.valueOf( "@studentId" );
  8. stringArray.add( studentId );
  9. }

代码示例来源:origin: com.atlassian.jira.plugins/jira-fisheye-plugin

  1. public List parse(FishEyeDocumentHolder docHolder) throws IOException {
  2. Document doc = docHolder.getDoc();
  3. List projects = new ArrayList();
  4. List rows = doc.selectNodes("/projects/projectData");
  5. for (Iterator rowIterator = rows.iterator(); rowIterator.hasNext();) {
  6. Node row = (Node) rowIterator.next();
  7. String key = row.valueOf("key");
  8. String name = row.valueOf("name");
  9. String defaultRepositoryName = row.valueOf("defaultRepositoryName");
  10. int id = Integer.parseInt(row.valueOf("id"));
  11. int permissionSchemeId = Integer.parseInt(row.valueOf("permissionSchemeId"));
  12. boolean allowReviewersToJoin = Boolean.valueOf(row.valueOf("allowReviewersToJoin")).booleanValue();
  13. projects.add(new CrucibleProjectImpl(new Integer(id), key, name, defaultRepositoryName,
  14. new Integer(permissionSchemeId), allowReviewersToJoin));
  15. }
  16. return projects;
  17. }

代码示例来源:origin: junicorn/conf

  1. public String attrValue(String strXPath) {
  2. Node n = document.selectSingleNode(strXPath);
  3. if (n != null) {
  4. return (n.valueOf("@value"));
  5. } else {
  6. return null;
  7. }
  8. }

代码示例来源:origin: com.github.becauseQA/becauseQA-utils

  1. public static String getNodeAttributeValue(String xpath, String attributeName) {
  2. Node xPathNode = getXPathNode(xpath);
  3. return xPathNode.valueOf("@" + attributeName);
  4. }

代码示例来源:origin: net.sf.tacos/tacos-core

  1. /**
  2. * Get category listing.
  3. * @return The category list
  4. */
  5. public synchronized List getCategories() {
  6. if (document == null) throw new IllegalStateException("No document set, call setResource and initialize.");
  7. if (cachedCategoryList == null) {
  8. List nodes = document.selectNodes("/sitemap/category[@name]");
  9. cachedCategoryList = new ArrayList(nodes.size());
  10. for(int i = 0, size = nodes.size(); i < size; i++) {
  11. String category = ((Node)nodes.get(i)).valueOf("@name");
  12. cachedCategoryList.add(category);
  13. }
  14. }
  15. return cachedCategoryList;
  16. }

代码示例来源:origin: com.atlassian.refapp/platform-ctk-plugin

  1. /**
  2. * Get the platform version.
  3. *
  4. * @return the platform version.
  5. */
  6. public static String getPlatformVersion() throws RuntimeException {
  7. Document document = readPlatformVersionDocument();
  8. String xPath = "/platform";
  9. List<Node> nodes = document.selectNodes(xPath);
  10. return nodes.get(0).valueOf("@version");
  11. }

代码示例来源:origin: com.github.becausetesting/commons

  1. public String getNodeAttributeValue(String xpath, String attribute) {
  2. // or use the xpath to get the attribute value://foo/bar/author/@name
  3. String attributeValue = null;
  4. Element rootElement = document.getRootElement();
  5. String namespace = rootElement.getNamespaceURI();
  6. if (namespace != null) {
  7. DefaultXPath defaultXPath = new DefaultXPath(xpath);
  8. Map<String, String> namespaces = new TreeMap<String, String>();
  9. namespaces.put("ns", namespace);
  10. defaultXPath.setNamespaceURIs(namespaces);
  11. attributeValue = defaultXPath.selectSingleNode(document).valueOf("@" + attribute);
  12. } else {
  13. attributeValue = rootElement.selectSingleNode(xpath).valueOf("@" + attribute);
  14. }
  15. return attributeValue;
  16. }

代码示例来源:origin: com.atlassian.ext/atlassian-plugin-repository-confluence-plugin

  1. protected SortedMap parseHitMapXml(String hitMapXml) throws Exception
  2. {
  3. SortedMap hitMap = new TreeMap();
  4. Document dom4jXPath = DocumentHelper.parseText(hitMapXml);
  5. List node = dom4jXPath.selectNodes("/response/increment");
  6. Iterator iterator = node.iterator();
  7. while (iterator.hasNext())
  8. {
  9. Node o = (Node) iterator.next();
  10. Node dateNode = o.selectSingleNode("date");
  11. XStream xStream = new XStream();
  12. xStream.setClassLoader(getClass().getClassLoader());
  13. Date date = (Date)xStream.fromXML(dateNode.asXML());
  14. String hitsString = o.valueOf("hits");
  15. hitMap.put(date, hitsString);
  16. }
  17. return hitMap;
  18. }

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

  1. protected void testValueOf(Element documentTest, Element context,
  2. Element valueOf) throws Exception {
  3. String xpath = valueOf.attributeValue("select");
  4. String description = "valueOf: " + xpath;
  5. String expected = valueOf.getText();
  6. String result = testContext.valueOf(xpath);
  7. log(description);
  8. log("\texpected: " + expected + " result: " + result);
  9. assertEquals(description, expected, result);
  10. }

相关文章