determining whether a specified character is a character according to production 2 of the XML 1.0 specification. - Java XML

Java examples for XML:XML String

Description

determining whether a specified character is a character according to production 2 of the XML 1.0 specification.

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        char c = 'a';
        System.out.println(isXMLCharacter(c));
    }//from www . j  a  v  a  2  s .  co m

    /**
     * This is a utility function for determining whether a specified 
     * character is a character according to production 2 of the 
     * XML 1.0 specification.
     *  
     * <p>Copied from org.jdom.Verifier.
     * 
     * <p>Copyright (C) 2000-2004 Jason Hunter & Brett McLaughlin.
     * All rights reserved.
     *
     * @param c <code>char</code> to check for XML compliance
     * @return <code>boolean</code> true if it's a character, 
     *                                false otherwise
     */
    public static boolean isXMLCharacter(char c) {

        if (c == '\n')
            return true;
        if (c == '\r')
            return true;
        if (c == '\t')
            return true;

        if (c < 0x20)
            return false;
        if (c <= 0xD7FF)
            return true;
        if (c < 0xE000)
            return false;
        if (c <= 0xFFFD)
            return true;
        if (c < 0x10000)
            return false;
        if (c <= 0x10FFFF)
            return true;

        return false;
    }
}

Related Tutorials