Indicates if the given MIME type is related to XML or not. - Android XML

Android examples for XML:XML Node

Description

Indicates if the given MIME type is related to XML or not.

Demo Code


//package com.java2s;

public class Main {


    /**//from   ww  w .j  a  v a2  s . co m
     * Indicates if the given MIME type is related to XML or not.
     * <p>
     * XML MIME types :
     * </p>
     * <ul>
     * <li>"<tt>text/xml</tt>",</li>
     * <li>"<tt>application/xml</tt>",</li>
     * <li>"<tt>image/svg+xml</tt>",</li>
     * <li>etc</li>
     * </ul>
     * <p>
     * Non-XML MIME types :
     * </p>
     * <ul>
     * <li>"<tt>application/xml-dtd</tt>",</li>
     * <li>"<tt>application/xml-external-parsed-entity</tt>",</li>
     * <li>etc</li>
     * </ul>
     *
     * @param mimeType
     *            The MIME type to test.
     * @return <code>true</code> if the MIME type contains the string "xml" not
     *         followed by "-", <code>false</code> otherwise.
     */
    public static boolean isXMLMimeType(String mimeType) {
        int index = mimeType.indexOf("xml");
        if (index != -1 && (index + 3 < mimeType.length()) ? mimeType
                .charAt(index + 3) != '-' : true) {
            // "application/xml", "text/xml", "image/svg+xml",
            // "application/xhtml+xml", etc
            // but not "application/xml-dtd",
            // "application/xml-external-parsed-entity" etc
            return true;
        } else {
            return false;
        }
    }
}

Related Tutorials