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

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

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

Node.getChildNodes介绍

[英]A NodeList that contains all children of this node. If there are no children, this is a NodeList containing no nodes.
[中]包含此节点所有子节点的NodeList。如果没有子节点,则这是一个不包含任何节点的NodeList

代码示例

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

private void parse(Document doc) {
  NodeList nodeList = doc.getChildNodes();
  for (int count = 0; count < nodeList.getLength(); count++) {
    Node node = nodeList.item(count);
    if (node.getNodeType() == Node.ELEMENT_NODE
        && node.hasChildNodes()) {
      parseAttrList(node.getChildNodes());
    }
  }
}

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

public static void removeChildren(Node e) {
 NodeList list = e.getChildNodes();
 for (int i = 0; i < list.getLength(); i++) {
  Node n = list.item(i);
  e.removeChild(n);
 }
}
private static void getMatchingNodes(Node node, Pattern[] nodePath, int cur, List<Node> res) {

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

private static String getChildElementValue(
    final String tagName,
    final Element element) {
  Node tagNode = element.getElementsByTagName(tagName).item(0);
  if ( tagNode == null )
    return null;
  NodeList nodes= tagNode.getChildNodes();
  Node node = (Node)nodes.item(0); 
   return node.getNodeValue();    
}

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

public static String text(Node node) {
  if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) {
    return node.getNodeValue();
  }
  if (node.hasChildNodes()) {
    return text(node.getChildNodes());
  }
  return "";
}

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

public Stream<XmlNode> children() {
  NodeList children = this.node.getChildNodes();
  return IntStream.range(0, children.getLength())
      .mapToObj(children::item)
      .map(XmlNode::new);
}

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

Mockito.when( node.getNodeName() ).thenReturn( "directory" );
  Node child = Mockito.mock( Node.class );
  Mockito.when( node.getFirstChild() ).thenReturn( child );
  Mockito.when( child.getNodeValue() ).thenReturn( directory );
Mockito.when( jobNode.getChildNodes() ).thenReturn( nodeList );

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

/** If the child node doesn't exist, it is created. */
private static Node getFirstChildNodeByName (Node parent, String child) {
  NodeList childNodes = parent.getChildNodes();
  for (int i = 0; i < childNodes.getLength(); i++) {
    if (childNodes.item(i).getNodeName().equals(child)) {
      return childNodes.item(i);
    }
  }
  Node newNode = parent.getOwnerDocument().createElement(child);
  if (childNodes.item(0) != null)
    return parent.insertBefore(newNode, childNodes.item(0));
  else
    return parent.appendChild(newNode);
}

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

private void populateContent(Node item, Object object) {
  for (int i = 0; i < item.getChildNodes().getLength(); i++) {
   Node child = item.getChildNodes().item(i);
   if (child instanceof Text) {
    setText(object, (Text) child);
   }
  }
 }

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

/** If the child node doesn't exist, it is created. */
private static Node getFirstChildNodeByName (Node parent, String child) {
  NodeList childNodes = parent.getChildNodes();
  for (int i = 0; i < childNodes.getLength(); i++) {
    if (childNodes.item(i).getNodeName().equals(child)) {
      return childNodes.item(i);
    }
  }
  Node newNode = parent.getOwnerDocument().createElement(child);
  if (childNodes.item(0) != null)
    return parent.insertBefore(newNode, childNodes.item(0));
  else
    return parent.appendChild(newNode);
}

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

@Override
public int jjtGetChildIndex() {
  org.w3c.dom.Node parent = node.getParentNode();
  NodeList childNodes = parent.getChildNodes();
  for (int i = 0; i < childNodes.getLength(); i++) {
    if (node == childNodes.item(i)) {
      return i;
    }
  }
  throw new IllegalStateException("This node is not a child of its parent: " + node);
}

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

private List<Node> getChildrenTags(final Node node, final String tagName) {
 List<Node> children = new ArrayList<>();
 for (int i = 0; i < node.getChildNodes().getLength(); i++) {
  Node childNode = node.getChildNodes().item(i);
  if (childNode.getNodeName().equalsIgnoreCase(tagName)) {
   children.add(childNode);
  }
 }
 return children;
}

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

public static String getJustText(Node text)
{
 StringBuilder sb = new StringBuilder();
 NodeList textElems = text.getChildNodes();
 for(int i = 0; i < textElems.getLength(); i++)
 {
  Node child = textElems.item(i);
  String str = child.getTextContent();
  //replace single occurrence of \n with " ", double occurrences with a single one.
  str = str.replaceAll("\n(?!\n)", " ");
  str = str.replaceAll("_", ""); //bug fix for sentence splitting
  sb.append(str + " ");
 }
 return sb.toString();
}

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

private void readPackageConfigFromXml(Node node) throws IOException {
  NodeList childNodes = node.getChildNodes();
  if (childNodes.getLength() > 0) {
    for (int j = 0, n = childNodes.getLength(); j < n; j++) {
      Node child = childNodes.item(j);
      if (child.getNodeType() == Node.ELEMENT_NODE) {
        Element check = (Element) child;
        String tagName = check.getTagName();
        String value = check.getAttribute(ATTR_VALUE);
        String name = check.getAttribute(ATTR_NAME);
        if (tagName.equals(ATTR_CONFIG_FIELD)) {
          mPackageFields.put(name, value);
        } else {
          System.err.println("unknown package config tag " + tagName);
        }
      }
    }
  }
}

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

private void trimNode(final Node node) {
  NodeList children = node.getChildNodes();
  for (int i = children.getLength() - 1; i >= 0; i--) {
    trimChild(node, children.item(i));
  }
}

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

private static String parseTextNode(Node exampleNode) {
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < exampleNode.getChildNodes().getLength(); i++) {
      Node node = exampleNode.getChildNodes().item(i);
      if (node.getNodeType() == Node.CDATA_SECTION_NODE || node.getNodeType() == Node.TEXT_NODE) {
        buffer.append(node.getNodeValue());
      }
    }
    return buffer.toString().trim();
  }
}

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

/**
 * Searches for all immediate children with the given name
 */
protected static List<Node> getChildrenByName(Node node, String name) {
  List<Node> matches = new ArrayList<>();
  NodeList children = node.getChildNodes();
  // search children
  for (int i = 0; i < children.getLength(); i++) {
    Node child = children.item(i);
    if (child.getNodeName().equals(name)) {
      matches.add(child);
    }
  }
  return matches;
}

代码示例来源:origin: apache/geode

/** Get the string contained in the first text child of the node. */
private static String getNodeValue(final Node node) {
 NodeList childNodes = node.getChildNodes();
 for (int index = 0; index < childNodes.getLength(); index++) {
  Node childNode = childNodes.item(index);
  if (childNode.getNodeType() == Node.TEXT_NODE) {
   return childNode.getNodeValue();
  }
 }
 return EMPTY_VALUE;
}

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

public static Iterator<Node> findChildren(Node node, String name) {
 List<Node> result = Lists.newArrayList();
 NodeList children = node.getChildNodes();
 for (int i = 0; i < children.getLength(); i++) {
  Node n = children.item(i);
  if (name.equals(n.getNodeName())) {
   result.add(n);
  }
 }
 return result.iterator();
}

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

private void parseAttrList(NodeList nodeList) {
  for (int count = 0; count < nodeList.getLength(); count++) {
    Node tempNode = nodeList.item(count);
    if (tempNode.getNodeType() == Node.ELEMENT_NODE
        && tempNode.hasAttributes()
        && tempNode.hasChildNodes()) {
      String name = null;
      NamedNodeMap nodeMap = tempNode.getAttributes();
      for (int i = 0; i < nodeMap.getLength(); i++) {
        Node node = nodeMap.item(i);
        if (node.getNodeName().equals("name")) {
          name = node.getNodeValue();
          break;
        }
      }
      if (name != null && tempNode.getNodeName().equals("attr")) {
        parseValues(name, tempNode.getChildNodes());
      } else {
        parseAttrList(tempNode.getChildNodes());
      }
    }
  }
}

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

private void readLibPatternsFromXml(Node node) throws IOException {
  NodeList childNodes = node.getChildNodes();
  if (childNodes.getLength() > 0) {
    for (int j = 0, n = childNodes.getLength(); j < n; j++) {
      Node child = childNodes.item(j);
      if (child.getNodeType() == Node.ELEMENT_NODE) {
        Element check = (Element) child;
        String tagName = check.getTagName();
        String value = check.getAttribute(ATTR_VALUE);
        if (tagName.equals(ATTR_PATTERN)) {
          addToPatterns(value, mSoFilePattern);
        } else {
          System.err.println("unknown dex tag " + tagName);
        }
      }
    }
  }
}

相关文章