Package org.geotools.xsd
Class StreamingParser
- Object
- 
- StreamingParser
 
- 
 public class StreamingParser extends Object XML parser capable of streaming.Performs the same task as Parser, with the addition that objects are streamed back to the client. Streaming can occur in a number of different modes.As an example consider the following gml document: <test:TestFeatureCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml" xmlns:test="http://www.geotools.org/test" xsi:schemaLocation="http://www.geotools.org/test test.xsd"> <gml:featureMember> <test:TestFeature fid="0"> ... </test:TestFeature> </gml:featureMember> <gml:featureMember> <test:TestFeature fid="1"> ... </test:TestFeature> </gml:featureMember> <gml:featureMember> <test:TestFeature fid="2"> .... </test:TestFeature> </gml:featureMember> </test:TestFeatureCollection>And suppose we want to stream back each feature as it is parsed.1. Element NameObjects are streamed back when an element of a particular name has been parsed.Configuration configuration = new GMLConfiguration(); QName elementName = new QName( "http://www.geotools.org/test", "TestFeature" ); StreamingParser parser = new StreamingParser( configuration, elementName ); Feature f = null; while ( ( f = parser.parse() ) != null ) { ... }2. TypeObjects are streamed back when an element has been parsed into an object of a particular type.Configuration configuration = new GMLConfiguration(); StreamingParser parser = new StreamingParser( configuration, Feature.class ); Feature f = null; while ( ( f = parser.parse() ) != null ) { ... }3. Xpath ExpressionObjects are streamed back when an element has been parsed which matches a particular xpath expression.Configuration configuration = new GMLConfiguration(); String xpath = "//TestFeature"; StreamingParser parser = new StreamingParser( configuration, xpath ); Feature f = null; while ( ( f = parser.parse() ) != null ) { ... }PullParseroffers similar functionality out of a pull parser instead of a SAX parser, it's supposed to be better, but won't (yet) cover the entire functionality offered byStreamingParser- Author:
- Justin Deoliveira, The Open Planning Project
 
- 
- 
Constructor SummaryConstructors Modifier Constructor Description StreamingParser(Configuration configuration, InputStream input, Class type)Creates a new instance of the type based streaming parser.StreamingParser(Configuration configuration, InputStream input, String xpath)Creates a new instance of the xpath based streaming parser.StreamingParser(Configuration configuration, InputStream input, QName elementName)Creates a new instance of the element name based streaming parser.protectedStreamingParser(Configuration configuration, InputStream input, StreamingParserHandler handler)Internal constructor.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description Objectparse()Streams the parser to the next element in the instance document which matches the xpath query specified in the contstructor.voidsetEntityResolver(EntityResolver entityResolver)
 
- 
- 
- 
Constructor Detail- 
StreamingParserpublic StreamingParser(Configuration configuration, InputStream input, Class type) throws ParserConfigurationException, SAXException Creates a new instance of the type based streaming parser.- Parameters:
- configuration- Object representing the configuration of the parser.
- input- The input stream representing the instance document to be parsed.
- type- The type of parsed objects to stream back.
- Throws:
- ParserConfigurationException
- SAXException
 
 - 
StreamingParserpublic StreamingParser(Configuration configuration, InputStream input, QName elementName) throws ParserConfigurationException, SAXException Creates a new instance of the element name based streaming parser.- Parameters:
- configuration- Object representing the configuration of the parser.
- input- The input stream representing the instance document to be parsed.
- elementName- The name of elements to stream back.
- Throws:
- ParserConfigurationException
- SAXException
 
 - 
StreamingParserpublic StreamingParser(Configuration configuration, InputStream input, String xpath) throws ParserConfigurationException, SAXException Creates a new instance of the xpath based streaming parser.- Parameters:
- configuration- Object representing the configuration of the parser.
- input- The input stream representing the instance document to be parsed.
- xpath- An xpath expression which dictates how the parser streams objects back to the client.
- Throws:
- ParserConfigurationException
- SAXException
 
 - 
StreamingParserprotected StreamingParser(Configuration configuration, InputStream input, StreamingParserHandler handler) throws ParserConfigurationException, SAXException Internal constructor.
 
- 
 - 
Method Detail- 
setEntityResolverpublic void setEntityResolver(EntityResolver entityResolver) 
 - 
parsepublic Object parse() Streams the parser to the next element in the instance document which matches the xpath query specified in the contstructor. This method returns null when there are no more objects to stream.- Returns:
- The next object in the stream, or null if no such object is available.
 
 
- 
 
-