Package org.basex.util
Class XMLToken
java.lang.Object
org.basex.util.XMLToken
This class provides convenience operations for XML-specific character
operations.
- Author:
- BaseX Team 2005-21, BSD License, Christian Gruen
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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 for the specified entity ornull.static booleanisChar(int ch) Checks if the specified character is an XML letter.static booleanisId(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 booleanisName(byte[] value) Checks if the specified token is a valid name.static booleanisNCChar(int ch) Checks if the specified character is an XML letter.static booleanisNCName(byte[] value) Checks if the specified token is a valid NCName.static booleanisNCStartChar(int ch) Checks if the specified character is a name start character, as required e.g.static booleanisNMToken(byte[] value) Checks if the specified token is a valid NMToken.static booleanisQName(byte[] value) Checks if the specified token is a valid QName.static booleanisStartChar(int ch) Checks if the specified character is an XML first-letter.static booleanvalid(int ch) Checks if the specified character is a valid XML 1.0 character.
-
Method Details
-
valid
public static boolean valid(int ch) Checks if the specified character is a valid XML 1.0 character.- Parameters:
ch- the letter to be checked- Returns:
- result of check
-
isNCStartChar
public static boolean isNCStartChar(int ch) Checks if the specified character is a name start character, as required e.g. by QName and NCName.- Parameters:
ch- character- Returns:
- result of check
-
isNCChar
public static boolean isNCChar(int ch) Checks if the specified character is an XML letter.- Parameters:
ch- character- Returns:
- result of check
-
isStartChar
public static boolean isStartChar(int ch) Checks if the specified character is an XML first-letter.- Parameters:
ch- the letter to be checked- Returns:
- result of check
-
isChar
public static boolean isChar(int ch) Checks if the specified character is an XML letter.- Parameters:
ch- the letter to be checked- 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 meta data.- Parameters:
name- nameidref- 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 encodedlax- 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- namelax- lax decoding- Returns:
- cached QName, or
nullif not successful
-
getEntity
public static byte[] getEntity(byte[] key) Returns the unicode for the specified entity ornull.- Parameters:
key- key- Returns:
- unicode
-