Parsing
Consider the following filter document:
<Filter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ogc="http://www.opengis.net/ogc" xmlns="http://www.opengis.net/ogc" xsi:schemaLocation="http://www.opengis.net/ogc filter.xsd"> <PropertyIsEqualTo> <PropertyName>testString</PropertyName> <Literal>2</Literal> </PropertyIsEqualTo> </Filter>
To parse the document:
//create the parser with the filter 1.0 configuration Configuration configuration = new org.geotools.filter.v1_0.OGCConfiguration(); Parser parser = new Parser( configuration ); //the xml instance document above InputStream xml = ... //parse Filter filter = (Filter) parser.parse( xml );
Encoding
Consider the following filter:
FilterFactory ff = CommonFactoryFinder.getFilterFactory( null ); PropertyName propertyName = ff.property( "testString" ); Literal literal = ff.literal( 2 ); PropertyIsEqualTo filter = ff.equals( propertyName, literal );
To encode the filter:
//create the encoder with the filter 1.0 configuration org.geotools.xml.Configuration = new org.geotools.filter.v1_0.OGCConfiguration(); org.geotools.xml.Encoder encoder = new org.geotools.xml.Encoder( configuration ); //create an output stream OutputStream xml = ... //encode encoder.encode( filter, org.geotools.filter.v1_0.OGC.FILTER, xml );
Filter 1.1
The Parsing and Encoding process is identical for filter 1.1 as for filter 1.0. The only difference is changing package references from org.geotools.filter.v1_0 to org.geotools.filter.v1_1.