获取子节点

@param node
节点
@param expression
相对于node的路径
@return NodeList
962993
public NodeList getNodeList(Object node, String expression) {
		return (NodeList) evalXPath(expression, node, XPathConstants.NODESET);
	}
1270568
public static ArrayList<Element> getChildElements(Node node) {
        ArrayList<Element> childElements = new ArrayList<>();
        NodeList childNodes = node.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            if (childNodes.item(i) instanceof Element) {
                childElements.add((Element) childNodes.item(i));
            }
        }
        return childElements;
    }
550877
function getAllExpressionStatements(node) {
  console.assert(node.body && node.body.body);
  var expressionStatements = [];
  node.body.body.forEach(function(childNode) {
    if (childNode.type == 'ExpressionStatement') {
      expressionStatements.push(childNode);
    } else if (childNode.body) {
      var childExpressions = getAllExpressionStatements(childNode);
      expressionStatements.push.apply(expressionStatements, childExpressions);
    }
  });
  return expressionStatements;
}
1090338
public static String rewrite(String expression) throws InvalidExpressionException {

        ExpressionTree expTree = parseToTree(expression);

        expTree.reduce();

        return expTree.toString();
    }
752136
public Boolean getBoolean(Object node, String expression) {
		return (Boolean) evalXPath(expression, node, XPathConstants.BOOLEAN);
	}
48485
def expressions(self):
        
        if self._expressions is None:
            expressions = [n.expression for n in self.nodes]
            expressions = [e for e in expressions if e]
            self._expressions = expressions
        return self._expressions
405866
public static NodeList xpathNodeList(Node document, XPathExpression xpathExpression) throws XPathException, MarshallingException
    {
        return (NodeList) executeXPath(document, xpathExpression, XPathConstants.NODESET);
    }
817293
protected NodeList getTagChildren(String tagName, Element element) {
        return element.getNamespaceURI() == null ? element.getElementsByTagName(tagName) : element.getElementsByTagNameNS(
            element.getNamespaceURI(), tagName);
    }
94623
private static final ExpressionTree parseToTree(String expression) throws InvalidExpressionException {

        ExpressionParser parser = new ExpressionParser();
        parser.parse(expression);

        return new ExpressionTree(parser.getVar(), parser.getTokens());
    }
1180876
public static List<Node> getSiblings(Node parent, Node element) {
		List<Node> result = new ArrayList<>();
		NodeList list = parent.getChildNodes();

		for (int i = 0; i < list.getLength(); i++) {
			Node el = list.item(i);

			if (el.getNodeName().equals(element.getNodeName())) {
				result.add(el);
			}
		}

		return result;
	}
128115
private static void getLeafNodes(
        TreeModel treeModel, Object node, Collection<Object> leafNodes)
    {
        if (node == null)
        {
            return;
        }
        int childCount = treeModel.getChildCount(node);
        if (childCount == 0)
        {
            leafNodes.add(node);
        }
        else
        {
            for (int i = 0; i < childCount; i++)
            {
                Object child = treeModel.getChild(node, i);
                getLeafNodes(treeModel, child, leafNodes);
            }
        }
    }
808144
public Node getNode(Object node, String expression) {
		return (Node) evalXPath(expression, node, XPathConstants.NODE);
	}
628016
@Nullable
  private static Node findExpressionRoot(Node subExpression) {
    Node child = subExpression;
    for (Node current : child.getAncestors()) {
      Node parent = current.getParent();
      switch (current.getToken()) {
          // Supported expression roots:
          // SWITCH and IF can have multiple children, but the CASE, DEFAULT,
          // or BLOCK will be encountered first for any of the children other
          // than the condition.
        case EXPR_RESULT:
        case IF:
        case SWITCH:
        case RETURN:
        case THROW:
          Preconditions.checkState(child.isFirstChildOf(current));
          return current;

        case VAR:
          // Normalization will remove LABELs from VARs.
        case LET:
        case CONST:
          if (NodeUtil.isAnyFor(parent)) {
            break; // Name declarations may not be roots if they're for-loop initializers.
          }
          return current;

          // Any of these indicate an unsupported expression:
        case FOR:
          if (child.isFirstChildOf(current)) {
            // Only the initializer of a for-loop could possibly be decomposed since the other
            // statements need to execute each iteration.
            return current;
          }
          // fall through
        case FOR_IN:
        case FOR_OF:
        case FOR_AWAIT_OF:
        case DO:
        case WHILE:
        case SCRIPT:
        case BLOCK:
        case LABEL:
        case CASE:
        case DEFAULT_CASE:
        case PARAM_LIST:
          return null;

        default:
          break;
      }
      child = current;
    }

    throw new IllegalStateException("Unexpected AST structure.");
  }
79577
public NodeList nodelist() throws javax.xml.transform.TransformerException
  {

    error(XPATHErrorResources.ER_CANT_CONVERT_TO_NODELIST,
          new Object[]{ getTypeString() });  //"Can not convert "+getTypeString()+" to a NodeList!");

    return null;
  }
1174666
@NonNull
    public static SelectResult.As expression(@NonNull Expression expression) {
        if (expression == null) {
            throw new IllegalArgumentException("expression cannot be null.");
        }
        return new SelectResult.As(expression);
    }
441573
public static List<QueryExprMeta> parse(String expression) {
        QueryParser parser = parser(tokens(expression));
        try {
            return parse(parser);
        } catch (ParseCancellationException | RecognitionException e) {
            RecognitionException err;
            if (e instanceof ParseCancellationException) {
                err = (RecognitionException) e.getCause();
            } else {
                err = (RecognitionException) e;
            }
            throw new QuerySyntaxException(
                    Messages.get("dsl.parse.err", err.getOffendingToken().getCharPositionInLine()),
                    e
            );
        }
    }
537821
@Nullable
    public static Node findNode(@NotNull final Node rootNode, @NotNull final XPath xPath,
            @NotNull final String expression) {
        Contract.requireArgNotNull("rootNode", rootNode);
        Contract.requireArgNotNull("xPath", xPath);
        Contract.requireArgNotNull("expression", expression);
        try {
            return (Node) xPath.compile(expression).evaluate(rootNode, XPathConstants.NODE);
        } catch (final XPathExpressionException ex) {
            throw new RuntimeException("Failed to read node: " + expression, ex);
        }
    }