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;
            }
        } else if (event.type == PullParser.END_DOCUMENT) {
            input.close();
            println("results: {total}, title: {title}");
        }
    }
}
parser.parse();
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);
The seek and forward functions can be chained together, for example,
parser.seek("child", 3).forward(2);

See Also:
Event

Profile: common

Script Variable Summary

accessnametypeCan ReadCan InitCan WriteDefault Valuedescription
publicCDATAInteger

Value of Event.type indicating CDATA in an XML document

publicDEFAULT_ENCODINGString

The default character encoding is utf-8

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

publicFALSEInteger

Value of Event.type indicating a JSON false value

publicINTEGERInteger

Value of Event.type indicating a JSON integer

publicJSONString

Value of documentType for JSON

publicNULLInteger

Value of Event.type indicating a JSON null value

publicNUMBERInteger

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

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

publicUNKNOWNInteger

An unknown event, possibly a syntax error in an XML or JSON document

publicXMLString

Value of documentType for XML

Variable Summary

accessnametypeCan ReadCan InitCan WriteDefault Valuedescription
public-read protectedcharacterEncodingStringsubclasssubclass

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-read protectedcolumnIntegersubclasssubclass

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.

 
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

 
public-read protectedeventEventsubclasssubclass

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

publicignoreWhiteSpaceBooleanfalse

Set to true to ignore whitespaces and new lines for a TEXT event.

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.

 
public-read protectedlineIntegersubclasssubclass

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.

 
publiconEventfunction(:Event):Voidnull

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

Inherited Variables

Function Summary

public forward(n: Integer) : PullParser

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
Returns
PullParser
the current parser instance to allow chaining of seek, and forward, . For example,
parser.seek("child").forward(2);
 
public forward() : PullParser

Move forward to the next Event.

Move forward to the next Event.

Returns
PullParser
the current parser instance to allow chaining of seek, and forward, . For example,
parser.seek("child").forward();
 
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) : PullParser

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 or String if documentType is XML or a String if documentType is JSON. The namespace is ignored if the element is a String and the documentType is XML.
Returns
PullParser
the current parser instance to allow chaining of seek, and forward, . For example,
parser.seek("child").forward();
 
public seek(element: java.lang.Object, level: Integer) : PullParser

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.
Returns
PullParser
the current parser instance to allow chaining of seek, and forward, . For example,
parser.seek("child", 3).forward();
 
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