public class

XMLTokener

extends JSONTokener
java.lang.Object
   ↳ org.json.JSONTokener
     ↳ org.json.XMLTokener

Class Overview

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

Summary

Fields
public static final HashMap entity The table of entity values.
Public Constructors
XMLTokener(String s)
Construct an XMLTokener from a string.
Public Methods
String nextCDATA()
Get the text in the CDATA block.
Object nextContent()
Get the next XML outer token, trimming whitespace.
Object nextEntity(char ampersand)
Return the next entity.
Object nextMeta()
Returns the next XML meta token.
Object nextToken()
Get the next XML Token.
boolean skipPast(String to)
Skip characters until past the requested string.
[Expand]
Inherited Methods
From class org.json.JSONTokener
From class java.lang.Object

Fields

public static final HashMap entity

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

Public Constructors

public XMLTokener (String s)

Construct an XMLTokener from a string.

Parameters
s A source string.

Public Methods

public String nextCDATA ()

Get the text in the CDATA block.

Returns
  • The string up to the ]]>.
Throws
JSONException If the ]]> is not found.

public Object nextContent ()

Get 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

public Object nextEntity (char ampersand)

Return 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.

public Object nextMeta ()

Returns 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.

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.

Returns
  • a String or a Character.
Throws
JSONException If the XML is not well formed.

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
JSONException