Class XMLToken


  • public final class XMLToken
    extends Object
    This class provides convenience operations for XML-specific character operations.
    Author:
    BaseX Team 2005-23, BSD License, Christian Gruen
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] decode​(byte[] name, boolean lax)
      Decodes an NCName to a string.
      static byte[] encode​(byte[] name, boolean lax)
      Encodes a string to a valid NCName.
      static byte[] getEntity​(byte[] key)
      Returns the unicode string for the specified entity or null.
      static int invalid​(byte[] token)
      Checks if the specified token contains invalid XML 1.0 characters.
      static boolean isChar​(int cp)
      Checks if the specified character is an XML letter.
      static boolean isId​(byte[] name, boolean idref)
      Checks if the specified name is an id/idref attribute (idref: local name must contain 'idref'; id: local name must contain 'if', but not 'idref').
      static boolean isName​(byte[] value)
      Checks if the specified token is a valid name.
      static boolean isNCChar​(int cp)
      Checks if the specified character is an XML letter.
      static boolean isNCName​(byte[] value)
      Checks if the specified token is a valid NCName.
      static boolean isNCStartChar​(int cp)
      Checks if the specified character is a name start character, as required e.g.
      static boolean isNMToken​(byte[] value)
      Checks if the specified token is a valid NMToken.
      static boolean isQName​(byte[] value)
      Checks if the specified token is a valid QName.
      static boolean isStartChar​(int cp)
      Checks if the specified character is an XML first-letter.
      static Object similarEntity​(byte[] key)
      Returns the most similar entity.
      static boolean valid​(int cp)
      Checks if the specified character is a valid XML 1.0 character.
    • Method Detail

      • valid

        public static boolean valid​(int cp)
        Checks if the specified character is a valid XML 1.0 character.
        Parameters:
        cp - codepoint of the character
        Returns:
        result of check
      • isNCStartChar

        public static boolean isNCStartChar​(int cp)
        Checks if the specified character is a name start character, as required e.g. by QName and NCName.
        Parameters:
        cp - codepoint of the character
        Returns:
        result of check
      • isNCChar

        public static boolean isNCChar​(int cp)
        Checks if the specified character is an XML letter.
        Parameters:
        cp - codepoint of the character
        Returns:
        result of check
      • isStartChar

        public static boolean isStartChar​(int cp)
        Checks if the specified character is an XML first-letter.
        Parameters:
        cp - codepoint of the character
        Returns:
        result of check
      • isChar

        public static boolean isChar​(int cp)
        Checks if the specified character is an XML letter.
        Parameters:
        cp - codepoint of the character
        Returns:
        result of check
      • isNCName

        public static boolean isNCName​(byte[] value)
        Checks if the specified token is a valid NCName.
        Parameters:
        value - value to be checked
        Returns:
        result of check
      • isName

        public static boolean isName​(byte[] value)
        Checks if the specified token is a valid name.
        Parameters:
        value - value to be checked
        Returns:
        result of check
      • isNMToken

        public static boolean isNMToken​(byte[] value)
        Checks if the specified token is a valid NMToken.
        Parameters:
        value - value to be checked
        Returns:
        result of check
      • isQName

        public static boolean isQName​(byte[] value)
        Checks if the specified token is a valid QName.
        Parameters:
        value - value to be checked
        Returns:
        result of check
      • isId

        public static boolean isId​(byte[] name,
                                   boolean idref)
        Checks if the specified name is an id/idref attribute (idref: local name must contain 'idref'; id: local name must contain 'if', but not 'idref'). The correct approach would be to gather all id/idref attributes and store them as metadata.
        Parameters:
        name - name
        idref - id/idref flag
        Returns:
        result of check
      • encode

        public static byte[] encode​(byte[] name,
                                    boolean lax)
        Encodes a string to a valid NCName.
        Parameters:
        name - token to be encoded
        lax - lax encoding (lossy, but better readable)
        Returns:
        valid NCName
      • decode

        public static byte[] decode​(byte[] name,
                                    boolean lax)
        Decodes an NCName to a string.
        Parameters:
        name - name
        lax - lax decoding
        Returns:
        cached QName, or null if not successful
      • invalid

        public static int invalid​(byte[] token)
        Checks if the specified token contains invalid XML 1.0 characters.
        Parameters:
        token - the token to be checked
        Returns:
        invalid character or -1
      • getEntity

        public static byte[] getEntity​(byte[] key)
        Returns the unicode string for the specified entity or null.
        Parameters:
        key - key
        Returns:
        unicode string
      • similarEntity

        public static Object similarEntity​(byte[] key)
        Returns the most similar entity.
        Parameters:
        key - key
        Returns:
        most similar entity or null