Code example for Node

Methods: getNextSibling, getNodeType, getParentNode

0
 
    } 
 
    /*protected*/ int processNextNodeType(Node node)
        throws XmlPullParserException { 
      switch (node.getNodeType()) {
        case (Node.ATTRIBUTE_NODE): {
          throw new IllegalArgumentException("ATTRIBUTE_NODE");
        } 
        case (Node.CDATA_SECTION_NODE): {
          return navigateToNextNode(node);
        } 
        case (Node.COMMENT_NODE): {
          return navigateToNextNode(node);
        } 
        case (Node.DOCUMENT_FRAGMENT_NODE): {
          throw new IllegalArgumentException("DOCUMENT_FRAGMENT_NODE");
        } 
        case (Node.DOCUMENT_NODE): {
          throw new IllegalArgumentException("DOCUMENT_NODE");
        } 
        case (Node.DOCUMENT_TYPE_NODE): {
          throw new IllegalArgumentException("DOCUMENT_TYPE_NODE");
        } 
        case (Node.ELEMENT_NODE): {
          currentNode = node;
          return START_TAG;
        } 
        case (Node.ENTITY_NODE): {
          throw new IllegalArgumentException("ENTITY_NODE");
        } 
        case (Node.ENTITY_REFERENCE_NODE): {
          throw new IllegalArgumentException("ENTITY_REFERENCE_NODE");
        } 
        case (Node.NOTATION_NODE): {
          throw new IllegalArgumentException("DOCUMENT_TYPE_NODE");
        } 
        case (Node.PROCESSING_INSTRUCTION_NODE): {
          throw new IllegalArgumentException("DOCUMENT_TYPE_NODE");
        } 
        case (Node.TEXT_NODE): {
          if (isWhitespace(node.getNodeValue())) {
            // Skip whitespaces 
            return navigateToNextNode(node);
          } else { 
            currentNode = node;
            return TEXT;
          } 
        } 
        default: { 
          throw new RuntimeException(
              "Robolectric -> Unknown node type: " + 
                  node.getNodeType() + ".");
        } 
      } 
    } 
 
    /** 
     * Navigate to the next node after a node and all of his 
     * children have been explored. 
     * <p/> 
     * <p>If the node has unexplored siblings navigate to the 
     * next sibling. Otherwise return to its parent. 
     * 
     * @param node the node which was just explored. 
     * @return {@link XmlPullParserException#START_TAG} if the given 
     *         node has siblings, {@link XmlPullParserException#END_TAG} 
     *         if the node has no unexplored siblings or 
     *         {@link XmlPullParserException#END_DOCUMENT} if the explored 
     *         was the root document. 
     * @throws XmlPullParserException if the parser fails to 
     *                                parse the next node. 
     */ 
    int navigateToNextNode(Node node)
        throws XmlPullParserException { 
      Node nextNode = node.getNextSibling();
      if (nextNode != null) {
        // Move to the next siblings 
        return processNextNodeType(nextNode);
      } else { 
        // Goes back to the parent 
        if (document.getDocumentElement().equals(node)) {
          currentNode = null;
          return END_DOCUMENT;
        } 
        currentNode = node.getParentNode();
        return END_TAG;
      } 
    } 
 
    public void require(int type, String namespace, String name)