code: private static void validateEntities(org.w3c.dom.Element document, JsonNode entityJson) throws InvalidInputException,
        ProcessingException {
      XPathFactory xPathfactory = XPathFactory.newInstance();
      XPath xpath = xPathfactory.newXPath();
  
      NodeList nodes;
      try {
        XPathExpression expr = xpath.compile("//@data-entity-id");
        nodes = (NodeList) expr.evaluate(document, XPathConstants.NODESET);
      } catch (XPathExpressionException e) {
        throw new ProcessingException("Internal error processing document tree: " + e.getMessage());
      }
  
      for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        String entityId = ((org.w3c.dom.Attr) node).getValue();
  
        JsonNode entityNode = entityJson.findPath(entityId);
        if (entityNode.isMissingNode()) {
          throw new InvalidInputException("Error processing EntityJSON: "
              + "no entity data provided for \"data-entity-id\"=\"" + entityId + "\"");
        } else if (!entityNode.isObject()) {
          throw new InvalidInputException("Error processing EntityJSON: "
              + "the node \"" + entityId + "\" has to be an object");
        }
      }
    }
docs: Check whether <i>data-entity-id</i> attributes in the message match EntityJSON entities.