org.json.XML Class Reference

List of all members.

Static Public Member Functions

static String escape (String string)
static void noSpace (String string) throws JSONException
static JSONObject toJSONObject (String string) throws JSONException
static String toString (Object o) throws JSONException
static String toString (Object o, String tagName) throws JSONException

Static Public Attributes

static final Character AMP = new Character('&')
static final Character APOS = new Character('\'')
static final Character BANG = new Character('!')
static final Character EQ = new Character('=')
static final Character GT = new Character('>')
static final Character LT = new Character('<')
static final Character QUEST = new Character('?')
static final Character QUOT = new Character('"')
static final Character SLASH = new Character('/')

Detailed Description

This provides static methods to convert an XML text into a JSONObject, and to covert a JSONObject into an XML text.

Author:
JSON.org
Version:
2010-04-08

Member Function Documentation

static String org.json.XML.escape ( String  string  )  [static]

Replace special characters with XML escapes:

 & (ampersand) is replaced by &amp;
 < (less than) is replaced by &lt;
 > (greater than) is replaced by &gt;
 " (double quote) is replaced by &quot;
 
Parameters:
string The string to be escaped.
Returns:
The escaped string.
static void org.json.XML.noSpace ( String  string  )  throws JSONException [static]

Throw an exception if the string contains whitespace. Whitespace is not allowed in tagNames and attributes.

Parameters:
string 
Exceptions:
JSONException 
static JSONObject org.json.XML.toJSONObject ( String  string  )  throws JSONException [static]

Convert a well-formed (but not necessarily valid) XML string into a JSONObject. Some information may be lost in this transformation because JSON is a data format and XML is a document format. XML uses elements, attributes, and content text, while JSON uses unordered collections of name/value pairs and arrays of values. JSON does not does not like to distinguish between elements and attributes. Sequences of similar elements are represented as JSONArrays. Content text may be placed in a "content" member. Comments, prologs, DTDs, and <[ [ ]]> are ignored.

Parameters:
string The source string.
Returns:
A JSONObject containing the structured data from the XML string.
Exceptions:
JSONException 
static String org.json.XML.toString ( Object  o,
String  tagName 
) throws JSONException [static]

Convert a JSONObject into a well-formed, element-normal XML string.

Parameters:
o A JSONObject.
tagName The optional name of the enclosing tag.
Returns:
A string.
Exceptions:
JSONException 
static String org.json.XML.toString ( Object  o  )  throws JSONException [static]

Convert a JSONObject into a well-formed, element-normal XML string.

Parameters:
o A JSONObject.
Returns:
A string.
Exceptions:
JSONException 

Member Data Documentation

final Character org.json.XML.AMP = new Character('&') [static]

The Character '&'.

final Character org.json.XML.APOS = new Character('\'') [static]

The Character '''.

final Character org.json.XML.BANG = new Character('!') [static]

The Character '!'.

final Character org.json.XML.EQ = new Character('=') [static]

The Character '='.

final Character org.json.XML.GT = new Character('>') [static]

The Character '>'.

final Character org.json.XML.LT = new Character('<') [static]

The Character '<'.

final Character org.json.XML.QUEST = new Character('?') [static]

The Character '?'.

final Character org.json.XML.QUOT = new Character('"') [static]

The Character '"'.

final Character org.json.XML.SLASH = new Character('/') [static]

The Character '/'.