spf.setValidating(false);
SAXParser parser = spf.newSAXParser();
parser.parse(f, contentHandler);
Schema schema = contentHandler.getSchema();
Element geomElement = schema.getElements()[0].findChildElement("GEOM");
GeometryFactory factory=new GeometryFactory();
LinearRing ring = factory.createLinearRing(new Coordinate[]{
new Coordinate(0,0),
new Coordinate(10,0),
new Coordinate(0,10),
new Coordinate(0,0)
});
Polygon polygon = factory.createPolygon(ring, new LinearRing[0]);
polygon.setUserData("EPSG:4326");
MultiPolygon geom = factory.createMultiPolygon(new Polygon[]{polygon});
geom.setUserData("EPSG:4326");
final StringWriter writer = new StringWriter();
// DocumentWriter.writeDocument(geom, schema, writer, new HashMap());
PrintHandler output=new PrintHandler(){
public void characters(char[] arg0, int arg1, int arg2) throws IOException {
writer.write(arg0, arg1, arg2);
}
public void characters(String s) throws IOException {
writer.write(s);
}
public void element(URI namespaceURI, String localName, Attributes attributes) throws IOException {
}
public void endDocument() throws IOException {
}
public void endElement(URI namespaceURI, String localName) throws IOException {
writer.write("</"+localName+">");
}
public Element findElement(Object value) {
return null;
}
public Element findElement(String name) {
return null;
}
public Schema getDocumentSchema() {
return null;
}
public Object getHint(Object key) {
return null;
}
public void ignorableWhitespace(char[] arg0, int arg1, int arg2) throws IOException {
}
public void startDocument() throws IOException {
}
public void startElement(URI namespaceURI, String localName, Attributes attributes) throws IOException {
writer.write("<"+localName);
if( attributes!=null ){
for( int i=0; i<attributes.getLength(); i++){
writer.write(" "+attributes.getLocalName(i)+"="+attributes.getValue(i));
}
}
writer.write(">");
}
};
geomElement.getType().encode(geomElement, geom, output, new HashMap());
String expected="<GEOM><MultiPolygon srsName=EPSG:4326><polygonMember><Polygon srsName=EPSG:4326><outerBoundaryIs><LinearRing><coordinates decimal=. cs=, ts= >0.0,0.0 10.0,0.0 0.0,10.0 0.0,0.0</coordinates></LinearRing></outerBoundaryIs></Polygon></polygonMember></MultiPolygon></GEOM>";
assertEquals(expected, writer.toString());
}