public class StreamingParser extends Object
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.
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 ) { ... }
Configuration configuration = new GMLConfiguration(); StreamingParser parser = new StreamingParser( configuration, Feature.class ); Feature f = null; while ( ( f = parser.parse() ) != null ) { ... }
Configuration configuration = new GMLConfiguration(); String xpath = "//TestFeature"; StreamingParser parser = new StreamingParser( configuration, xpath ); Feature f = null; while ( ( f = parser.parse() ) != null ) { ... }
PullParser
offers 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 by StreamingParser
Modifier | Constructor and Description |
---|---|
|
StreamingParser(Configuration configuration,
InputStream input,
Class type)
Creates a new instance of the type based streaming parser.
|
|
StreamingParser(Configuration configuration,
InputStream input,
QName elementName)
Creates a new instance of the element name based streaming parser.
|
protected |
StreamingParser(Configuration configuration,
InputStream input,
StreamingParserHandler handler)
Internal constructor.
|
|
StreamingParser(Configuration configuration,
InputStream input,
String xpath)
Creates a new instance of the xpath based streaming parser.
|
Modifier and Type | Method and Description |
---|---|
Object |
parse()
Streams the parser to the next element in the instance document which matches the xpath query
specified in the contstructor.
|
void |
setEntityResolver(EntityResolver entityResolver) |
public StreamingParser(Configuration configuration, InputStream input, Class type) throws ParserConfigurationException, SAXException
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.ParserConfigurationException
SAXException
public StreamingParser(Configuration configuration, InputStream input, QName elementName) throws ParserConfigurationException, SAXException
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.ParserConfigurationException
SAXException
public StreamingParser(Configuration configuration, InputStream input, String xpath) throws ParserConfigurationException, SAXException
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.ParserConfigurationException
SAXException
protected StreamingParser(Configuration configuration, InputStream input, StreamingParserHandler handler) throws ParserConfigurationException, SAXException
public void setEntityResolver(EntityResolver entityResolver)
public Object parse()
Copyright © 1996–2022 Geotools. All rights reserved.