Package org.json
Class XMLTokener
- java.lang.Object
-
- org.json.JSONTokener
-
- org.json.XMLTokener
-
public class XMLTokener extends JSONTokener
The XMLTokener extends the JSONTokener to provide additional methods for the parsing of XML texts.- Version:
- 2015-12-09
-
-
Field Summary
Fields Modifier and Type Field Description private XMLParserConfigurationconfigurationstatic java.util.HashMap<java.lang.String,java.lang.Character>entityThe table of entity values.
-
Constructor Summary
Constructors Constructor Description XMLTokener(java.io.Reader r)Construct an XMLTokener from a Reader.XMLTokener(java.io.Reader r, XMLParserConfiguration configuration)Construct an XMLTokener from a Reader and an XMLParserConfiguration.XMLTokener(java.lang.String s)Construct an XMLTokener from a string.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static booleanisValidDecimal(java.lang.String s)Check if a string contains only valid decimal digits.private static booleanisValidHex(java.lang.String s)Check if a string contains only valid hexadecimal digits.java.lang.StringnextCDATA()Get the text in the CDATA block.java.lang.ObjectnextContent()Get the next XML outer token, trimming whitespace.java.lang.ObjectnextEntity(char ampersand)Return the next entity. These entities are translated to Characters: & ' > < ".java.lang.ObjectnextMeta()Returns the next XML meta token. This is used for skipping over <!...> and <?...?> structures.java.lang.ObjectnextToken()Get the next XML Token. These tokens are found inside of angle brackets. It may be one of these characters: / > = ! ? or it may be a string wrapped in single quotes or double quotes, or it may be a name.private static intparseDecimalEntity(java.lang.String e)Parse a decimal numeric character reference (e.g., "{").private static intparseHexEntity(java.lang.String e)Parse a hexadecimal numeric character reference (e.g., "઼").voidskipPast(java.lang.String to)Skip characters until past the requested string.(package private) static java.lang.StringunescapeEntity(java.lang.String e)Unescape an XML entity encoding;-
Methods inherited from class org.json.JSONTokener
back, close, dehexchar, end, getJsonParserConfiguration, getPrevious, more, next, next, next, nextClean, nextSimpleValue, nextString, nextTo, nextTo, nextValue, setJsonParserConfiguration, skipTo, syntaxError, syntaxError, toString
-
-
-
-
Field Detail
-
entity
public static final java.util.HashMap<java.lang.String,java.lang.Character> entity
The table of entity values. It initially contains Character values for amp, apos, gt, lt, quot.
-
configuration
private XMLParserConfiguration configuration
-
-
Constructor Detail
-
XMLTokener
public XMLTokener(java.io.Reader r)
Construct an XMLTokener from a Reader.- Parameters:
r- A source reader.
-
XMLTokener
public XMLTokener(java.lang.String s)
Construct an XMLTokener from a string.- Parameters:
s- A source string.
-
XMLTokener
public XMLTokener(java.io.Reader r, XMLParserConfiguration configuration)Construct an XMLTokener from a Reader and an XMLParserConfiguration.- Parameters:
r- A source reader.configuration- the configuration that can be used to set certain flags
-
-
Method Detail
-
nextCDATA
public java.lang.String nextCDATA() throws JSONExceptionGet the text in the CDATA block.- Returns:
- The string up to the
]]>. - Throws:
JSONException- If the]]>is not found.
-
nextContent
public java.lang.Object nextContent() throws JSONExceptionGet the next XML outer token, trimming whitespace. There are two kinds of tokens: the
character which begins a markup tag, and the content text between markup tags.'<'- Returns:
- A string, or a
Character, or null if there is no more source text.'<' - Throws:
JSONException- if a called function has an error
-
nextEntity
public java.lang.Object nextEntity(char ampersand) throws JSONExceptionReturn the next entity. These entities are translated to Characters: & ' > < ".- Parameters:
ampersand- An ampersand character.- Returns:
- A Character or an entity String if the entity is not recognized.
- Throws:
JSONException- If missing ';' in XML entity.
-
unescapeEntity
static java.lang.String unescapeEntity(java.lang.String e) throws JSONExceptionUnescape an XML entity encoding;- Parameters:
e- entity (only the actual entity value, not the preceding & or ending ;- Returns:
- the unescaped entity string
- Throws:
JSONException- if the entity is malformed
-
parseHexEntity
private static int parseHexEntity(java.lang.String e) throws JSONExceptionParse a hexadecimal numeric character reference (e.g., "઼").- Parameters:
e- entity string starting with '#' (e.g., "#x1F4A9")- Returns:
- the Unicode code point
- Throws:
JSONException- if the format is invalid
-
parseDecimalEntity
private static int parseDecimalEntity(java.lang.String e) throws JSONExceptionParse a decimal numeric character reference (e.g., "{").- Parameters:
e- entity string starting with '#' (e.g., "#123")- Returns:
- the Unicode code point
- Throws:
JSONException- if the format is invalid
-
isValidHex
private static boolean isValidHex(java.lang.String s)
Check if a string contains only valid hexadecimal digits.- Parameters:
s- the string to check- Returns:
- true if s is non-empty and contains only hex digits (0-9, a-f, A-F)
-
isValidDecimal
private static boolean isValidDecimal(java.lang.String s)
Check if a string contains only valid decimal digits.- Parameters:
s- the string to check- Returns:
- true if s is non-empty and contains only digits (0-9)
-
nextMeta
public java.lang.Object nextMeta() throws JSONExceptionReturns the next XML meta token. This is used for skipping over <!...> and <?...?> structures.- Returns:
Syntax characters (< > / = ! ?) are returned as Character, and strings and names are returned as Boolean. We don't care what the values actually are.- Throws:
JSONException- If a string is not properly closed or if the XML is badly structured.
-
nextToken
public java.lang.Object nextToken() throws JSONExceptionGet the next XML Token. These tokens are found inside of angle brackets. It may be one of these characters: / > = ! ? or it may be a string wrapped in single quotes or double quotes, or it may be a name.- Returns:
- a String or a Character.
- Throws:
JSONException- If the XML is not well formed.
-
skipPast
public void skipPast(java.lang.String to)
Skip characters until past the requested string. If it is not found, we are left at the end of the source with a result of false.- Parameters:
to- A string to skip past.
-
-