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

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

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

  1. private void parse(Document doc) {
  2. NodeList nodeList = doc.getChildNodes();
  3. for (int count = 0; count < nodeList.getLength(); count++) {
  4. Node node = nodeList.item(count);
  5. if (node.getNodeType() == Node.ELEMENT_NODE
  6. && node.hasChildNodes()) {
  7. parseAttrList(node.getChildNodes());
  8. }
  9. }
  10. }

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

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

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

  1. public String getSample( String strFunctionName, String strFunctionNameWithArgs ) {
  2. String sRC = "// Sorry, no Script available for " + strFunctionNameWithArgs;
  3. NodeList nl = dom.getElementsByTagName( "jsFunction" );
  4. for ( int i = 0; i < nl.getLength(); i++ ) {
  5. if ( nl.item( i ).getAttributes().getNamedItem( "name" ).getNodeValue().equals( strFunctionName ) ) {
  6. Node elSample = ( (Element) nl.item( i ) ).getElementsByTagName( "sample" ).item( 0 );
  7. if ( elSample.hasChildNodes() ) {
  8. return ( elSample.getFirstChild().getNodeValue() );
  9. }
  10. }
  11. }
  12. return sRC;
  13. }

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

  1. /**
  2. * Check if row contains non-empty cells
  3. *
  4. * @param rowElem
  5. * @return
  6. */
  7. protected boolean isRowEmpty( TableTableRowElement rowElem ) {
  8. NodeList cells = rowElem.getChildNodes();
  9. int cellsLen = cells.getLength();
  10. for ( int j = 0; j < cellsLen; j++ ) { // iterate over cells
  11. Node cell = cells.item( j );
  12. if ( cell instanceof TableTableCellElement ) {
  13. if ( cell.hasChildNodes() ) {
  14. return false;
  15. }
  16. }
  17. }
  18. return true;
  19. }

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

  1. while (child != null) {
  2. Node next = child.getNextSibling();
  3. if (child.hasChildNodes()) {
  4. if (collectorTextChild != null) {
  5. int type = child.getNodeType();
  6. if (type == Node.TEXT_NODE || type == Node.CDATA_SECTION_NODE ) {
  7. if (collectorTextChild != null) {
  8. if (collectorTextChildBuff.length() == 0) {
  9. collectorTextChildBuff.ensureCapacity(
  10. collectorTextChild.getNodeValue().length() + child.getNodeValue().length());
  11. collectorTextChildBuff.append(collectorTextChild.getNodeValue());
  12. collectorTextChildBuff.append(child.getNodeValue());

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

  1. Node n = attrs.item(i);
  2. String name = n.getNodeName();
  3. String value = n.getNodeValue();
  4. String value2 = n2.getNodeValue();
  5. boolean hasChildren = node.hasChildNodes();
  6. if (hasChildren != node2.hasChildNodes()) {
  7. throw ActiveMQClientMessageBundle.BUNDLE.oneNodeHasChildren();
  8. NodeList nl = node.getChildNodes();
  9. NodeList nl2 = node2.getChildNodes();

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

  1. /**
  2. * Recursively removes all comment nodes from the subtree.
  3. *
  4. * @see #simplify
  5. */
  6. static public void removeComments(Node parent) {
  7. Node child = parent.getFirstChild();
  8. while (child != null) {
  9. Node nextSibling = child.getNextSibling();
  10. if (child.getNodeType() == Node.COMMENT_NODE) {
  11. parent.removeChild(child);
  12. } else if (child.hasChildNodes()) {
  13. removeComments(child);
  14. }
  15. child = nextSibling;
  16. }
  17. }

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

  1. private String getNodeTextValue(Node n) {
  2. if(n.hasChildNodes()) {
  3. if(n.getFirstChild().getNodeName().equals("#text")) {
  4. return n.getFirstChild().getNodeValue();
  5. }
  6. }
  7. return "";
  8. }

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

  1. private void parseAttrList(NodeList nodeList) {
  2. for (int count = 0; count < nodeList.getLength(); count++) {
  3. Node tempNode = nodeList.item(count);
  4. if (tempNode.getNodeType() == Node.ELEMENT_NODE
  5. && tempNode.hasAttributes()
  6. && tempNode.hasChildNodes()) {
  7. String name = null;
  8. NamedNodeMap nodeMap = tempNode.getAttributes();
  9. for (int i = 0; i < nodeMap.getLength(); i++) {
  10. Node node = nodeMap.item(i);
  11. if (node.getNodeName().equals("name")) {
  12. name = node.getNodeValue();
  13. break;
  14. }
  15. }
  16. if (name != null && tempNode.getNodeName().equals("attr")) {
  17. parseValues(name, tempNode.getChildNodes());
  18. } else {
  19. parseAttrList(tempNode.getChildNodes());
  20. }
  21. }
  22. }
  23. }

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

  1. public String getSample( String strFunctionName, String strFunctionNameWithArgs ) {
  2. String sRC = "// Sorry, no Script available for " + strFunctionNameWithArgs;
  3. NodeList nl = dom.getElementsByTagName( "jsFunction" );
  4. for ( int i = 0; i < nl.getLength(); i++ ) {
  5. if ( nl.item( i ).getAttributes().getNamedItem( "name" ).getNodeValue().equals( strFunctionName ) ) {
  6. Node elSample = ( (Element) nl.item( i ) ).getElementsByTagName( "sample" ).item( 0 );
  7. if ( elSample.hasChildNodes() ) {
  8. return ( elSample.getFirstChild().getNodeValue() );
  9. }
  10. }
  11. }
  12. return sRC;
  13. }

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

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

  1. protected int findNrColumns( OdfTableRow row ) {
  2. int result = roughNrOfCols;
  3. if ( row != null ) {
  4. NodeList cells = row.getOdfElement().getChildNodes();
  5. if ( cells != null && cells.getLength() > 0 ) {
  6. int cellLen = cells.getLength();
  7. for ( int i = cellLen - 1; i >= 0; i-- ) {
  8. Node cell = cells.item( i );
  9. if ( cell instanceof TableTableCellElement ) {
  10. if ( !cell.hasChildNodes() ) {
  11. // last cell is empty - remove it from counter
  12. result -= ( (TableTableCellElement) cell ).getTableNumberColumnsRepeatedAttribute();
  13. } else {
  14. // get first non-empty cell from the end, break
  15. break;
  16. }
  17. }
  18. }
  19. }
  20. }
  21. return result;
  22. }

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

  1. if (pos.hasChildNodes())
  2. if(next!=null && DOCUMENT_TYPE_NODE==next.getNodeType())
  3. next=next.getNextSibling();
  4. if(ENTITY_REFERENCE_NODE!=pos.getNodeType())
  5. if(next!=null && DOCUMENT_TYPE_NODE==next.getNodeType())
  6. next=next.getNextSibling();
  7. XMLCharacterRecognizer.isWhiteSpace(n.getNodeValue());

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

  1. private String getContent(Node node) {
  2. if (node.hasChildNodes()) {
  3. return getContent(node.getChildNodes());
  4. }
  5. return node.getNodeValue();
  6. }

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

  1. /**
  2. * Recursively removes all processing instruction nodes from the subtree.
  3. *
  4. * @see #simplify
  5. */
  6. static public void removePIs(Node parent) {
  7. Node child = parent.getFirstChild();
  8. while (child != null) {
  9. Node nextSibling = child.getNextSibling();
  10. if (child.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
  11. parent.removeChild(child);
  12. } else if (child.hasChildNodes()) {
  13. removePIs(child);
  14. }
  15. child = nextSibling;
  16. }
  17. }

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

  1. private static void getMatchingNodes(Node node, String[] nodePath, int cur, List<Node> res) {
  2. if (cur < 0 || cur >= nodePath.length) return;
  3. boolean last = (cur == nodePath.length-1);
  4. String name = nodePath[cur];
  5. if (node.hasChildNodes()) {
  6. NodeList children = node.getChildNodes();
  7. for (int i = 0; i < children.getLength(); i++) {
  8. Node c = children.item(i);
  9. if (name.equals(c.getNodeName())) {
  10. if (last) {
  11. res.add(c);
  12. } else {
  13. getMatchingNodes(c, nodePath, cur+1, res);
  14. }
  15. }
  16. }
  17. }
  18. }

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

  1. private static void buildFunctionList() {
  2. hatFunctionsList = new Hashtable<String, String>();
  3. NodeList nlFunctions = dom.getElementsByTagName( "jsFunction" );
  4. for ( int i = 0; i < nlFunctions.getLength(); i++ ) {
  5. String strFunctionName = nlFunctions.item( i ).getAttributes().getNamedItem( "name" ).getNodeValue();
  6. Node elType = ( (Element) nlFunctions.item( i ) ).getElementsByTagName( "type" ).item( 0 );
  7. String strType = "";
  8. if ( elType.hasChildNodes() ) {
  9. strType = elType.getFirstChild().getNodeValue();
  10. }
  11. NodeList nlFunctionArgs = ( (Element) nlFunctions.item( i ) ).getElementsByTagName( "argument" );
  12. for ( int j = 0; j < nlFunctionArgs.getLength(); j++ ) {
  13. String strFunctionArgs = nlFunctionArgs.item( j ).getFirstChild().getNodeValue();
  14. hatFunctionsList.put( strFunctionName + "(" + strFunctionArgs + ")", strType );
  15. }
  16. if ( nlFunctionArgs.getLength() == 0 ) {
  17. hatFunctionsList.put( strFunctionName + "()", strType );
  18. }
  19. }
  20. }

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

  1. /**
  2. * Returns the text value of this block.
  3. **/
  4. public String getText() {
  5. if (_node.getNodeType() == Node.TEXT_NODE) {
  6. return _node.getNodeValue().trim();
  7. } else if (_node == null || !_node.hasChildNodes()) {
  8. return "";
  9. } else {
  10. return NodeUtils.asText( _node.getChildNodes() ).trim();
  11. }
  12. }

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

  1. public boolean responseNotEmpty(String response) throws ExecutionException {
  2. NodeList response_body;
  3. Document doc = getDocument(response);
  4. XPath xpath = XPathFactory.newInstance().newXPath();
  5. try {
  6. XPathExpression expr = xpath.compile("/response[@status='success']");
  7. response_body = (NodeList)expr.evaluate(doc, XPathConstants.NODESET);
  8. } catch (XPathExpressionException e) {
  9. throw new ExecutionException(e.getCause().getMessage());
  10. }
  11. if (response_body.getLength() > 0 &&
  12. (!response_body.item(0).getTextContent().equals("") || (response_body.item(0).hasChildNodes() && response_body.item(0).getFirstChild().hasChildNodes()))) {
  13. return true;
  14. } else {
  15. return false;
  16. }
  17. }

相关文章