JavaFX: Bringing Rich Experiences To All the Screens Of Your Life

Profile: desktop, common

Overview

A parser for structured data. The parser supplies a sequence of Events as it process the document under application control.

XML and JSON are the two data formats currently supported.

The parser can be used with the onEvent callback like this -

var total;
var title;
def parser = PullParser { 
    documentType: PullParser.XML; 
    input: anInputStreamThatContainsXML;
    onEvent: function(event: Event) {
        if (event.type == PullParser.START_ELEMENT) {
            if (event.qname.name == "ResultSet" and event.level == 0) {
                total = event.getAttributeValue(QName{name:"totalResultsAvailable"});
            }
        } else if (event.type == PullParser.END_ELEMENT) {
            if (event.qname.name == "Title" and event.level == 2) {
                title = event.text;
            }
        }
    }
}
parser.parse();
parser.input.close();
println("results: {total}, title: {title}");
The parser can also be used in "linear" mode where the application simply pulls events, discarding or skipping over those it is not interested in. The current event is always available as event or via the onEvent callback. For example,
parser.onEvent = function(event: Event) { println(event) }
parser.forward();
parser.forward(2);
parser.seek(QName{name:"child"});
parser.seek(QName{name:"child" namespace:"urn:some.namespace.uri"}, 2);

See Also:
Event

Profile: common

Variable Summary

accessnametypeCan ReadCan InitCan WriteDefault Valuedescription
publicCDATAInteger

Value of Event.type indicating CDATA in an XML document

public-readcharacterEncodingString

The character encoding as reported by the parser.

The character encoding as reported by the parser. Will be null if not supported by the underlying parser.

 
public-readcolumnInteger

The current column number in the source XML or JSON.

The current column number in the source XML or JSON. Will be zero if not supported by the underlying parser.

 
publicDEFAULT_ENCODINGString

The default character encoding is utf-8

publicdocumentTypeString

Set this variable to specify the type of content to be handled by the parser.

Set this variable to specify the type of content to be handled by the parser. XML and JSON are the only legal values at this time. XML is the default value. Setting this while a parse is in progress will reset the parser.

See Also:
XML, JSON

 
publicencodingString

Set this variable to specify the character encoding of content to be handled by the parser.

Set this variable to specify the character encoding of content to be handled by the parser. Setting this while a parse is in progress will reset the parser. The default encoding is specified by DEFAULT_ENCODING

See Also:
DEFAULT_ENCODING

 
publicEND_ARRAYInteger

Value of Event.type indicating the end of a JSON array

publicEND_ARRAY_ELEMENTInteger

Value of Event.type indicating the end of a JSON array element

publicEND_DOCUMENTInteger

Value of Event.type indicating the end of an XML or JSON document

publicEND_ELEMENTInteger

Value of Event.type indicating the end of an XML element or JSON object

publicEND_VALUEInteger

Value of Event.type indicating the end of a JSON object value

publicERRORInteger

Value of Event.type indicating a syntax error in an XML or JSON document

public-readeventEvent

The current parser event, which changes as the parser moves through the XML or JSON content.

publicFALSEInteger

Value of Event.type indicating a JSON false value

publicinputInputStream

Set this variable to provide the parser with the source of content to parse.

Set this variable to provide the parser with the source of content to parse. Setting this while a parse is in progress will reset the parser. It is the application's responsibility to close the stream when the parser is done.

 
publicINTEGERInteger

Value of Event.type indicating a JSON integer

publicJSONString

Value of documentType for JSON

public-readlineInteger

The current line number in the source XML or JSON.

The current line number in the source XML or JSON. Will be zero if not supported by the underlying parser.

 
publicNULLInteger

Value of Event.type indicating a JSON null value

publicNUMBERInteger

Value of Event.type indicating a JSON floating-point number

publiconEventfunction(:Event):Void

Callback, which if set to a non-null function, reports the current parse event to that function.

publicSTART_ARRAYInteger

Value of Event.type indicating the start of a JSON array

publicSTART_ARRAY_ELEMENTInteger

Value of Event.type indicating the start of a JSON array element

publicSTART_DOCUMENTInteger

Value of Event.type indicating the start of an XML or JSON document

publicSTART_ELEMENTInteger

Value of Event.type indicating the start of an XML element or JSON object

publicSTART_VALUEInteger

Value of Event.type indicating the start of a JSON object value

publicTEXTInteger

Value of Event.type indicating text in an XML or JSON element

publicTRUEInteger

Value of Event.type indicating a JSON true value

publicXMLString

Value of documentType for XML

Inherited Variables

Function Summary

public forward(n: Integer) : Void

Move forward, skipping over the specified number of Events.

Move forward, skipping over the specified number of Events.

Parameters
n
number of Events to skip over
 
public forward() : Void

Move forward to the next Event.

Move forward to the next Event.

 
public parse() : Void

Runs through all Events until the end of the document is reached.

Runs through all Events until the end of the document is reached.

 
public seek(element: java.lang.Object) : Void

Skip Events until the specified element is found.

Skip Events until the specified element is found.

Parameters
element
specifies the name of the XML element or JSON object to stop at. This needs to be a QName if documentType is XML or a String if documentType is JSON
 
public seek(element: java.lang.Object, level: Integer) : Void

Skip Events until the specified element is found at the specified level.

Skip Events until the specified element is found at the specified level.

Parameters
element
a QName if documentType is XML or a String if documentType is JSON that specifies the name of the XML element or JSON object to stop at.
level
the depth at which the specified element must be found.
 
public toString() : java.lang.String

A human-readable representation of the current state of the parser.

A human-readable representation of the current state of the parser.

Returns
String
A human-readable representation of the current state of the parser
 

Inherited Functions




Spec-Zone.ru - all specs in one place