code: public static String evaluateAsString(Node node, String xPathExpression, NamespaceContext nsContext) {
          String result = (String) evaluateExpression(node, xPathExpression, nsContext, XPathConstants.STRING);
  
          if (!StringUtils.hasText(result)) {
              //result is empty so check if the expression node really exists
              //if node does not exist an exception is thrown
              evaluateAsNode(node, xPathExpression, nsContext);
          }
  
          return result;
      }
docs: Evaluate XPath expression with result type String.
  @param node
  @param xPathExpression
  @param nsContext
  @return