protected Element extractMathMLElement(final NodeList resultNodeList, final boolean allowUpConversionOptionsElements) {
        /* Make sure there is exactly one MathML element, and any number of upconversion options
         * specifiers.
         */
        Element result = null;
        for (int i=0, size=resultNodeList.getLength(); i<size; i++) {
            Node node = resultNodeList.item(i);
            if (isMathMLElement(node)) {
                if (result!=null) {
                    return null;
                }
                result = (Element) node;
            }
            else if (node.getNodeType()==Node.TEXT_NODE && node.getNodeValue().trim().length()==0) {
                /* Ignore whitespace */
                continue;
            }
            else if (allowUpConversionOptionsElements
                    && node.getNodeType()==Node.ELEMENT_NODE
                    && SnuggleConstants.SNUGGLETEX_NAMESPACE.equals(node.getNamespaceURI())
                    && UpConversionUtilities.UPCONVERSION_OPTIONS_XML_LOCAL_NAME.equals(node.getLocalName())) {
                /* Allow <s:upconversion-options/> */
                continue;
            }
            else {
                /* Anything else is an not allowed */
                return null;
            }
        }
        return result;
    }