org.w3c.dom.Node.getNodeValue()方法的使用及代码示例

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

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

Node.getNodeValue介绍

[英]The value of this node, depending on its type; see the table above. When it is defined to be null, setting it has no effect, including if the node is read-only.
[中]此节点的值,取决于其类型;见上表。当定义为null时,将其设置为无效,包括节点是否为只读。

代码示例

代码示例来源:origin: Tencent/tinker

  1. private static String extractNameAttribute(Node node) {
  2. return node.getAttributes().getNamedItem("name").getNodeValue();
  3. }

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

  1. private List<String> extractUsesPermissionNames(NodeList usesPermissionNodes) {
  2. List<String> usesPermissionQualifiedNames = new ArrayList<>();
  3. for (int i = 0; i < usesPermissionNodes.getLength(); i++) {
  4. Node usesPermissionNode = usesPermissionNodes.item(i);
  5. Node nameAttribute = usesPermissionNode.getAttributes().getNamedItem("android:name");
  6. if (nameAttribute == null) {
  7. return null;
  8. }
  9. usesPermissionQualifiedNames.add(nameAttribute.getNodeValue());
  10. }
  11. return usesPermissionQualifiedNames;
  12. }

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

  1. /**
  2. * Extracts the text value from the given DOM element, ignoring XML comments.
  3. * <p>Appends all CharacterData nodes and EntityReference nodes into a single
  4. * String value, excluding Comment nodes. Only exposes actual user-specified
  5. * text, no default values of any kind.
  6. * @see CharacterData
  7. * @see EntityReference
  8. * @see Comment
  9. */
  10. public static String getTextValue(Element valueEle) {
  11. Assert.notNull(valueEle, "Element must not be null");
  12. StringBuilder sb = new StringBuilder();
  13. NodeList nl = valueEle.getChildNodes();
  14. for (int i = 0; i < nl.getLength(); i++) {
  15. Node item = nl.item(i);
  16. if ((item instanceof CharacterData && !(item instanceof Comment)) || item instanceof EntityReference) {
  17. sb.append(item.getNodeValue());
  18. }
  19. }
  20. return sb.toString();
  21. }

代码示例来源:origin: Tencent/tinker

  1. if (node.getNodeType() != Node.ELEMENT_NODE) {
  2. continue;
  3. String resourceType = node.getNodeName();
  4. if (resourceType.equals(ITEM_TAG)) {
  5. resourceType = node.getAttributes().getNamedItem("type").getNodeValue();
  6. if (resourceType.equals("id")) {
  7. resourceCollector.addIgnoreId(node.getAttributes().getNamedItem("name").getNodeValue());

代码示例来源:origin: skylot/jadx

  1. private void parseValues(String name, NodeList nodeList) {
  2. MAttr attr = null;
  3. for (int count = 0; count < nodeList.getLength(); count++) {
  4. Node tempNode = nodeList.item(count);
  5. if (tempNode.getNodeType() == Node.ELEMENT_NODE
  6. && tempNode.hasAttributes()) {
  7. if (attr == null) {
  8. if (tempNode.getNodeName().equals("enum")) {
  9. attr = new MAttr(MAttrType.ENUM);
  10. } else if (tempNode.getNodeName().equals("flag")) {
  11. attr = new MAttr(MAttrType.FLAG);
  12. NamedNodeMap attributes = tempNode.getAttributes();
  13. Node nameNode = attributes.getNamedItem("name");
  14. if (nameNode != null) {
  15. Node valueNode = attributes.getNamedItem("value");
  16. if (valueNode != null) {
  17. try {
  18. long key;
  19. String nodeValue = valueNode.getNodeValue();
  20. if (nodeValue.startsWith("0x")) {
  21. nodeValue = nodeValue.substring(2);
  22. key = Long.parseLong(nodeValue);
  23. attr.getValues().put(key, nameNode.getNodeValue());
  24. } catch (NumberFormatException e) {
  25. LOG.debug("Failed parse manifest number", e);

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

  1. private static HashMap<String, String> parseNodeAttributes(Node node) {
  2. final NamedNodeMap attributes = node.getAttributes();
  3. final int attrCount = attributes.getLength();
  4. final HashMap<String, String> receiverAttrs = new HashMap<>(attributes.getLength());
  5. for (int i = 0; i < attrCount; i++) {
  6. Node attribute = attributes.item(i);
  7. String value = attribute.getNodeValue();
  8. if (value != null) {
  9. receiverAttrs.put(attribute.getNodeName(), value);
  10. }
  11. }
  12. return receiverAttrs;
  13. }

代码示例来源:origin: aws/aws-sdk-java

  1. private static String getChildElementValue(
  2. final String tagName,
  3. final Element element) {
  4. Node tagNode = element.getElementsByTagName(tagName).item(0);
  5. if ( tagNode == null )
  6. return null;
  7. NodeList nodes= tagNode.getChildNodes();
  8. Node node = (Node)nodes.item(0);
  9. return node.getNodeValue();
  10. }

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

  1. @Override
  2. public Attribute next() {
  3. org.w3c.dom.Node attributeNode = attributes.item(index++);
  4. return new Attribute(XmlNodeWrapper.this,
  5. attributeNode.getNodeName(),
  6. attributeNode.getNodeValue());
  7. }

代码示例来源:origin: real-logic/simple-binary-encoding

  1. /**
  2. * Helper function that throws an exception when the attribute is not set.
  3. *
  4. * @param elementNode that should have the attribute
  5. * @param attrName that is to be looked up
  6. * @return value of the attribute
  7. * @throws IllegalArgumentException if the attribute is not present
  8. */
  9. public static String getAttributeValue(final Node elementNode, final String attrName)
  10. {
  11. final Node attrNode = elementNode.getAttributes().getNamedItemNS(null, attrName);
  12. if (attrNode == null || "".equals(attrNode.getNodeValue()))
  13. {
  14. throw new IllegalStateException(
  15. "Element '" + elementNode.getNodeName() + "' has empty or missing attribute: " + attrName);
  16. }
  17. return attrNode.getNodeValue();
  18. }

代码示例来源:origin: groovy/groovy-core

  1. public static String text(Node node) {
  2. if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) {
  3. return node.getNodeValue();
  4. }
  5. if (node.hasChildNodes()) {
  6. return text(node.getChildNodes());
  7. }
  8. return "";
  9. }

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

  1. private void visit( Node n ) throws SAXException {
  2. setCurrentLocation( n );
  3. // if a case statement gets too big, it should be made into a separate method.
  4. switch(n.getNodeType()) {
  5. case Node.CDATA_SECTION_NODE:
  6. case Node.TEXT_NODE:
  7. String value = n.getNodeValue();
  8. receiver.characters( value.toCharArray(), 0, value.length() );
  9. break;
  10. case Node.ELEMENT_NODE:
  11. visit( (Element)n );
  12. break;
  13. case Node.ENTITY_REFERENCE_NODE:
  14. receiver.skippedEntity(n.getNodeName());
  15. break;
  16. case Node.PROCESSING_INSTRUCTION_NODE:
  17. ProcessingInstruction pi = (ProcessingInstruction)n;
  18. receiver.processingInstruction(pi.getTarget(),pi.getData());
  19. break;
  20. }
  21. }

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

  1. private String text(Node n){
  2. String text = null;
  3. switch(n.getNodeType()){
  4. case Node.TEXT_NODE:
  5. text = n.getNodeValue();
  6. if(text != null) text = text.trim();
  7. break;
  8. case Node.CDATA_SECTION_NODE:
  9. text = n.getNodeValue();
  10. break;
  11. default:
  12. //AQUtility.debug("unknown", n);
  13. }
  14. if(text == null) text = "";
  15. return text;
  16. }

代码示例来源:origin: org.testng/testng

  1. private void populateAttributes(Node node, Object object) throws XPathExpressionException {
  2. for (int j = 0; j < node.getAttributes().getLength(); j++) {
  3. Node item = node.getAttributes().item(j);
  4. setProperty(object, item.getLocalName(), item.getNodeValue());
  5. }
  6. }

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

  1. private void parseUsedPermissions(Document manifestDocument) {
  2. NodeList elementsByTagName = manifestDocument.getElementsByTagName("uses-permission");
  3. int length = elementsByTagName.getLength();
  4. for (int i = 0; i < length; i++) {
  5. Node node = elementsByTagName.item(i).getAttributes().getNamedItem("android:name");
  6. usedPermissions.add(node.getNodeValue());
  7. }
  8. }

代码示例来源:origin: kiegroup/jbpm

  1. protected void readDataOutputAssociation(org.w3c.dom.Node xmlNode, SubProcessNode subProcessNode, Map<String, String> dataOutputs) {
  2. // sourceRef
  3. org.w3c.dom.Node subNode = xmlNode.getFirstChild();
  4. String from = subNode.getTextContent();
  5. // targetRef
  6. subNode = subNode.getNextSibling();
  7. String to = subNode.getTextContent();
  8. // transformation
  9. Transformation transformation = null;
  10. subNode = subNode.getNextSibling();
  11. if (subNode != null && "transformation".equals(subNode.getNodeName())) {
  12. String lang = subNode.getAttributes().getNamedItem("language").getNodeValue();
  13. String expression = subNode.getTextContent();
  14. DataTransformer transformer = transformerRegistry.find(lang);
  15. if (transformer == null) {
  16. throw new IllegalArgumentException("No transformer registered for language " + lang);
  17. }
  18. transformation = new Transformation(lang, expression, from);
  19. subNode = subNode.getNextSibling();
  20. }
  21. subProcessNode.addOutMapping(dataOutputs.get(from), to, transformation);
  22. }

代码示例来源:origin: dreamhead/moco

  1. private Optional<String[]> doExtract(final NodeList list) {
  2. List<String> values = newArrayList();
  3. for (int i = 0; i < list.getLength(); i++) {
  4. Node node = list.item(i);
  5. values.add(node.getNodeValue());
  6. }
  7. return of(values.toArray(new String[values.size()]));
  8. }
  9. }

代码示例来源:origin: stanfordnlp/CoreNLP

  1. /**
  2. * Fetches the value of a given attribute
  3. */
  4. public static String getAttributeValue(Node node, String attributeName) {
  5. try {
  6. return node.getAttributes().getNamedItem(attributeName).getNodeValue();
  7. } catch (Exception e) {
  8. }
  9. return null;
  10. }

代码示例来源:origin: Tencent/tinker

  1. private static String nodeToString(Node node, boolean isNoChild) {
  2. StringBuilder stringBuilder = new StringBuilder();
  3. if (node != null) {
  4. stringBuilder.append(node.getNodeName());
  5. NamedNodeMap namedNodeMap = node.getAttributes();
  6. stringBuilder.append(Constant.Symbol.MIDDLE_BRACKET_LEFT);
  7. int namedNodeMapLength = namedNodeMap.getLength();
  8. for (int j = 0; j < namedNodeMapLength; j++) {
  9. Node attributeNode = namedNodeMap.item(j);
  10. stringBuilder.append(Constant.Symbol.AT + attributeNode.getNodeName() + Constant.Symbol.EQUAL + attributeNode.getNodeValue());
  11. if (j < namedNodeMapLength - 1) {
  12. stringBuilder.append(Constant.Symbol.COMMA);
  13. }
  14. }
  15. stringBuilder.append(Constant.Symbol.MIDDLE_BRACKET_RIGHT);
  16. String value = StringUtil.nullToBlank(isNoChild ? node.getTextContent() : node.getNodeValue()).trim();
  17. if (StringUtil.isNotBlank(value)) {
  18. stringBuilder.append(Constant.Symbol.EQUAL + value);
  19. }
  20. }
  21. return stringBuilder.toString();
  22. }

代码示例来源:origin: nutzam/nutz

  1. /**
  2. * 获取该 XML 元素内所有的属性的值,按照Map的形式返回
  3. *
  4. * @param ele
  5. * XML 元素
  6. * @return 所有属性的值
  7. */
  8. public static Map<String, String> getAttrs(Element ele) {
  9. NamedNodeMap nodeMap = ele.getAttributes();
  10. Map<String, String> attrs = new HashMap<String, String>(nodeMap.getLength());
  11. for (int i = 0; i < nodeMap.getLength(); i++) {
  12. attrs.put(nodeMap.item(i).getNodeName(), nodeMap.item(i).getNodeValue());
  13. }
  14. return attrs;
  15. }

代码示例来源:origin: oracle/opengrok

  1. private String getValue(Node node) {
  2. if (node == null) {
  3. return null;
  4. }
  5. StringBuilder sb = new StringBuilder();
  6. Node n = node.getFirstChild();
  7. while (n != null) {
  8. if (n.getNodeType() == Node.TEXT_NODE) {
  9. sb.append(n.getNodeValue());
  10. }
  11. n = n.getNextSibling();
  12. }
  13. return sb.toString();
  14. }

相关文章