public static Map<Long, Message> findMessages(
        final Document document, final XPath xPath, final Map<String, Type> typeByNameMap)
        throws XPathExpressionException
    {
        final Map<Long, Message> messageByIdMap = new HashMap<>();
        final ObjectHashSet<String> distinctNames = new ObjectHashSet<>();

        forEach(
            (NodeList)xPath.compile(MESSAGE_XPATH_EXPR).evaluate(document, XPathConstants.NODESET),
            (node) -> addMessageWithIdCheck(distinctNames, messageByIdMap, new Message(node, typeByNameMap), node));

        if (messageByIdMap.isEmpty())
        {
            handleWarning(document.getDocumentElement(), "no messages found in document");
        }

        return messageByIdMap;
    }
Scan XML for all message definitions and save in map.

@param document      for the XML parsing.
@param xPath         for XPath expression reuse.
@param typeByNameMap to use for Type objects.
@return {@link java.util.Map} of schemaId to {@link Message}.
@throws XPathExpressionException on parsing error.
sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/XmlSchemaParser.java