Java Reference
In-Depth Information
framework will be driven by reasons other than the pure parsing and/or marshalling perform-
ance.
QUICK SUMMARY
1. There are many ways for Java EE applications to process programmatic data.
2. As these techniques provide more functionality to developers, the cost of the data
processing itself will increase. Don't let that dissuade you from choosing the right
paradigm for handling the data in your application.
Choosing a Parser
All programmatic data must be parsed. Whether applications use a parser directly, or indirec-
tly by using a marshalling framework, the choice of the parser is important in the overall per-
formance of the data operations.
Pull parsers
From a developer's perspective, it is usually easiest to use a pull parser. In the XML world,
these are known as StAX (Streaming API for XML) parsers. JSON-P provides only a pull
parser.
Pull parsers operate by retrieving data from the stream on demand. The basic pull parser for
the tests in this section has this loop as its main logic:
XMLStreamReader reader = staxFactory . createXMLStreamReader ( ins );
while
while ( reader . hasNext ()) {
reader . next ();
int
int state = reader . getEventType ();
switch
switch ( state ) {
case
case XMLStreamConstants . START_ELEMENT :
String s = reader . getLocalName ();
iif ( ITEM_ID . equals ( s )) {
isItemID = true
true ;
}
break
break ;
case
case XMLStreamConstants . CHARACTERS :
iif ( isItemID ) {
Search WWH ::




Custom Search