XML parser capable of streaming.
Performs the same task as
org.geotools.xml.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 Name
Objects 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. Type
Objects 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 Expression
Objects 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 ) {
...
}
author: Justin Deoliveira, The Open Planning Project |