Node Director
Static Public Member Functions | Static Public Attributes | List of all members
org.json.XML Class Reference

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

Static Public Member Functions

static String escape (String string)
 Replace special characters with XML escapes:
static JSONObject toJSONObject (String string) throws ParseException
 Convert a well-formed (but not necessarily valid) XML string into a JSONObject.
static String toString (Object o)
 Convert a JSONObject into a well-formed XML string.
static String toString (Object o, String tagName)
 Convert a JSONObject into a well-formed XML string.

Static Public Attributes

static final Character AMP = new Character('&')
 The Character '&'.
static final Character APOS = new Character('\'')
 The Character '''.
static final Character BANG = new Character('!')
 The Character '!'.
static final Character EQ = new Character('=')
 The Character '='.
static final Character GT = new Character('>')
 The Character '>'.
static final Character LT = new Character('<')
 The Character '<'.
static final Character QUEST = new Character('?')
 The Character '?'.
static final Character QUOT = new Character('"')
 The Character '"'.
static final Character SLASH = new Character('/')
 The 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
0.1

Member Function Documentation

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

Replace special characters with XML escapes:

& is replaced by &amp;
< is replaced by &lt;
> is replaced by &gt;
" is replaced by &quot;
Parameters
stringThe string to be escaped.
Returns
The escaped string.

Referenced by org.json.XML.toString().

static JSONObject org.json.XML.toJSONObject ( String  string) throws ParseException
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
stringThe source string.
Returns
A JSONObject containing the structured data from the XML string.
Exceptions
ParseException

References org.json.JSONTokener.more(), and org.json.JSONTokener.skipPast().

Referenced by org.json.Test.main().

static String org.json.XML.toString ( Object  o)
static

Convert a JSONObject into a well-formed XML string.

Parameters
oA JSONObject.
Returns
A string.

Referenced by org.json.Test.main(), and org.json.XML.toString().

static String org.json.XML.toString ( Object  o,
String  tagName 
)
static

Convert a JSONObject into a well-formed XML string.

Parameters
oA JSONObject.
tagNameThe optional name of the enclosing tag.
Returns
A string.

References org.json.XML.escape(), org.json.JSONArray.get(), org.json.JSONObject.get(), org.json.JSONObject.keys(), org.json.JSONArray.length(), org.json.JSONArray.opt(), and org.json.XML.toString().

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 '!'.

Referenced by org.json.XMLTokener.nextMeta(), and org.json.XMLTokener.nextToken().

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

The Character '='.

Referenced by org.json.XMLTokener.nextMeta(), and org.json.XMLTokener.nextToken().

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

The Character '>'.

Referenced by org.json.XMLTokener.nextMeta(), and org.json.XMLTokener.nextToken().

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

The Character '<'.

Referenced by org.json.XMLTokener.nextContent(), and org.json.XMLTokener.nextMeta().

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

The Character '?'.

Referenced by org.json.XMLTokener.nextMeta(), and org.json.XMLTokener.nextToken().

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

The Character '"'.

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

The Character '/'.

Referenced by org.json.XMLTokener.nextMeta(), and org.json.XMLTokener.nextToken().


The documentation for this class was generated from the following file: