XMLTokener

public class XMLTokener extends JSONTokener

The XMLTokener extends the JSONTokener to provide additional methods for the parsing of XML texts.

Author:JSON.org

Fields

entity

public static final java.util.HashMap entity

The table of entity values. It initially contains Character values for amp, apos, gt, lt, quot.

Constructors

XMLTokener

public XMLTokener(String s)

Construct an XMLTokener from a string.

Parameters:
  • s – A source string.

Methods

nextCDATA

public String nextCDATA()

Get the text in the CDATA block.

Throws:
Returns:

The string up to the ]]>.

nextContent

public Object nextContent()

Get the next XML outer token, trimming whitespace. There are two kinds of tokens: the ‘

Throws:
Returns:

A string, or a ‘

nextEntity

public Object nextEntity(char ampersand)

Return the next entity. These entities are translated to Characters: &  '  >  <  ".

Parameters:
  • ampersand – An ampersand character.
Throws:
Returns:

A Character or an entity String if the entity is not recognized.

nextMeta

public Object nextMeta()

Returns the next XML meta token. This is used for skipping over and ...?> structures.

Throws:
  • JSONException – If a string is not properly closed or if the XML is badly structured.
Returns:

Syntax characters (/ = ! ?) are returned as Character, and strings and names are returned as Boolean. We don’t care what the values actually are.

nextToken

public Object nextToken()

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.

Throws:
Returns:

a String or a Character.

skipPast

public boolean skipPast(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.
Throws: