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

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

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

Node.hasChildNodes介绍

[英]Returns whether this node has any children.
[中]返回此节点是否有子节点。

代码示例

代码示例来源: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: pmd/pmd

@Override
public int jjtGetNumChildren() {
  return node.hasChildNodes() ? node.getChildNodes().getLength() : 0;
}

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

public String getSample( String strFunctionName, String strFunctionNameWithArgs ) {
 String sRC = "// Sorry, no Script available for " + strFunctionNameWithArgs;
 NodeList nl = dom.getElementsByTagName( "jsFunction" );
 for ( int i = 0; i < nl.getLength(); i++ ) {
  if ( nl.item( i ).getAttributes().getNamedItem( "name" ).getNodeValue().equals( strFunctionName ) ) {
   Node elSample = ( (Element) nl.item( i ) ).getElementsByTagName( "sample" ).item( 0 );
   if ( elSample.hasChildNodes() ) {
    return ( elSample.getFirstChild().getNodeValue() );
   }
  }
 }
 return sRC;
}

代码示例来源: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: pentaho/pentaho-kettle

/**
 * Check if row contains non-empty cells
 *
 * @param rowElem
 * @return
 */
protected boolean isRowEmpty( TableTableRowElement rowElem ) {
 NodeList cells = rowElem.getChildNodes();
 int cellsLen = cells.getLength();
 for ( int j = 0; j < cellsLen; j++ ) { // iterate over cells
  Node cell = cells.item( j );
  if ( cell instanceof TableTableCellElement ) {
   if ( cell.hasChildNodes() ) {
    return false;
   }
  }
 }
 return true;
}

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

while (child != null) {
  Node next = child.getNextSibling();
  if (child.hasChildNodes()) {
    if (collectorTextChild != null) {
    int type = child.getNodeType();
    if (type == Node.TEXT_NODE || type == Node.CDATA_SECTION_NODE ) {
      if (collectorTextChild != null) {
        if (collectorTextChildBuff.length() == 0) {
          collectorTextChildBuff.ensureCapacity(
              collectorTextChild.getNodeValue().length() + child.getNodeValue().length());
          collectorTextChildBuff.append(collectorTextChild.getNodeValue());
        collectorTextChildBuff.append(child.getNodeValue());

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

Node n = attrs.item(i);
  String name = n.getNodeName();
  String value = n.getNodeValue();
   String value2 = n2.getNodeValue();
boolean hasChildren = node.hasChildNodes();
if (hasChildren != node2.hasChildNodes()) {
  throw ActiveMQClientMessageBundle.BUNDLE.oneNodeHasChildren();
  NodeList nl = node.getChildNodes();
  NodeList nl2 = node2.getChildNodes();

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

/**
 * Recursively removes all comment nodes from the subtree.
 *
 * @see #simplify
 */
static public void removeComments(Node parent) {
  Node child = parent.getFirstChild();
  while (child != null) {
    Node nextSibling = child.getNextSibling();
    if (child.getNodeType() == Node.COMMENT_NODE) {
      parent.removeChild(child);
    } else if (child.hasChildNodes()) {
      removeComments(child);
    }
    child = nextSibling;
  }
}

代码示例来源:origin: iipc/openwayback

private String getNodeTextValue(Node n) {
  if(n.hasChildNodes()) {
    if(n.getFirstChild().getNodeName().equals("#text")) {
      return n.getFirstChild().getNodeValue();
    }
  }
  return "";
}

代码示例来源: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: pentaho/pentaho-kettle

public String getSample( String strFunctionName, String strFunctionNameWithArgs ) {
 String sRC = "// Sorry, no Script available for " + strFunctionNameWithArgs;
 NodeList nl = dom.getElementsByTagName( "jsFunction" );
 for ( int i = 0; i < nl.getLength(); i++ ) {
  if ( nl.item( i ).getAttributes().getNamedItem( "name" ).getNodeValue().equals( strFunctionName ) ) {
   Node elSample = ( (Element) nl.item( i ) ).getElementsByTagName( "sample" ).item( 0 );
   if ( elSample.hasChildNodes() ) {
    return ( elSample.getFirstChild().getNodeValue() );
   }
  }
 }
 return sRC;
}

代码示例来源:origin: org.codehaus.groovy/groovy-xml

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: pentaho/pentaho-kettle

protected int findNrColumns( OdfTableRow row ) {
 int result = roughNrOfCols;
 if ( row != null ) {
  NodeList cells = row.getOdfElement().getChildNodes();
  if ( cells != null && cells.getLength() > 0 ) {
   int cellLen = cells.getLength();
   for ( int i = cellLen - 1; i >= 0; i-- ) {
    Node cell = cells.item( i );
    if ( cell instanceof TableTableCellElement ) {
     if ( !cell.hasChildNodes() ) {
      // last cell is empty - remove it from counter
      result -= ( (TableTableCellElement) cell ).getTableNumberColumnsRepeatedAttribute();
     } else {
      // get first non-empty cell from the end, break
      break;
     }
    }
   }
  }
 }
 return result;
}

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

if (pos.hasChildNodes()) 
  if(next!=null && DOCUMENT_TYPE_NODE==next.getNodeType())
   next=next.getNextSibling();
  if(ENTITY_REFERENCE_NODE!=pos.getNodeType())
    if(next!=null && DOCUMENT_TYPE_NODE==next.getNodeType())
     next=next.getNextSibling();
   XMLCharacterRecognizer.isWhiteSpace(n.getNodeValue());

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

private String getContent(Node node) {
  if (node.hasChildNodes()) {
    return getContent(node.getChildNodes());
  }
  return node.getNodeValue();
}

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

/**
 * Recursively removes all processing instruction nodes from the subtree.
 *
 * @see #simplify
 */
static public void removePIs(Node parent) {
  Node child = parent.getFirstChild();
  while (child != null) {
    Node nextSibling = child.getNextSibling();
    if (child.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
      parent.removeChild(child);
    } else if (child.hasChildNodes()) {
      removePIs(child);
    }
    child = nextSibling;
  }
}

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

private static void getMatchingNodes(Node node, String[] nodePath, int cur, List<Node> res) {
 if (cur < 0 || cur >= nodePath.length) return;
 boolean last = (cur == nodePath.length-1);
 String name = nodePath[cur];
 if (node.hasChildNodes()) {
  NodeList children = node.getChildNodes();
  for (int i = 0; i < children.getLength(); i++) {
   Node c = children.item(i);
   if (name.equals(c.getNodeName())) {
    if (last) {
     res.add(c);
    } else {
     getMatchingNodes(c, nodePath, cur+1, res);
    }
   }
  }
 }
}

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

private static void buildFunctionList() {
 hatFunctionsList = new Hashtable<String, String>();
 NodeList nlFunctions = dom.getElementsByTagName( "jsFunction" );
 for ( int i = 0; i < nlFunctions.getLength(); i++ ) {
  String strFunctionName = nlFunctions.item( i ).getAttributes().getNamedItem( "name" ).getNodeValue();
  Node elType = ( (Element) nlFunctions.item( i ) ).getElementsByTagName( "type" ).item( 0 );
  String strType = "";
  if ( elType.hasChildNodes() ) {
   strType = elType.getFirstChild().getNodeValue();
  }
  NodeList nlFunctionArgs = ( (Element) nlFunctions.item( i ) ).getElementsByTagName( "argument" );
  for ( int j = 0; j < nlFunctionArgs.getLength(); j++ ) {
   String strFunctionArgs = nlFunctionArgs.item( j ).getFirstChild().getNodeValue();
   hatFunctionsList.put( strFunctionName + "(" + strFunctionArgs + ")", strType );
  }
  if ( nlFunctionArgs.getLength() == 0 ) {
   hatFunctionsList.put( strFunctionName + "()", strType );
  }
 }
}

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

/**
 * Returns the text value of this block.
 **/
public String getText() {
  if (_node.getNodeType() == Node.TEXT_NODE) {
    return _node.getNodeValue().trim();
  } else if (_node == null || !_node.hasChildNodes()) {
    return "";
  } else {
    return NodeUtils.asText( _node.getChildNodes() ).trim();
  }
}

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

public boolean responseNotEmpty(String response) throws ExecutionException {
  NodeList response_body;
  Document doc = getDocument(response);
  XPath xpath = XPathFactory.newInstance().newXPath();
  try {
    XPathExpression expr = xpath.compile("/response[@status='success']");
    response_body = (NodeList)expr.evaluate(doc, XPathConstants.NODESET);
  } catch (XPathExpressionException e) {
    throw new ExecutionException(e.getCause().getMessage());
  }
  if (response_body.getLength() > 0 &&
    (!response_body.item(0).getTextContent().equals("") || (response_body.item(0).hasChildNodes() && response_body.item(0).getFirstChild().hasChildNodes()))) {
    return true;
  } else {
    return false;
  }
}

相关文章