I am using `org.geotools` version `2.7.0` and I am trying to get some shapefiles to `GML 3.1.1`. Sadly I got an exception:

    java.lang.RuntimeException: Encode failed for _Feature. Cause: INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified. 
	at org.geotools.xml.impl.ElementEncodeExecutor.visit(ElementEncodeExecutor.java:132)
	at org.geotools.xml.impl.BindingWalker$BindingExecutionChain.execute(BindingWalker.java:215)
	at org.geotools.xml.impl.BindingWalker.walk(BindingWalker.java:181)
	at org.geotools.xml.impl.BindingVisitorDispatch.walk(BindingVisitorDispatch.java:44)
	at org.geotools.xml.impl.ElementEncoder.encode(ElementEncoder.java:83)
	at org.geotools.xml.Encoder.encode(Encoder.java:1100)
	at org.geotools.xml.Encoder.encode(Encoder.java:836)
	at org.geotools.xml.Encoder.encode(Encoder.java:564)

Maybe it's a space or an accented char (shape's attributes are full of accented chars) but I am very new to geotools and GIS, this error is completely blocking me. I can't find a way to specify a charset to read data from shape (by set up `DataStore`) or to write data into GML file (by set up `Encoder`). What am I missing?



----------




I am trying to remove not allowed symbols from attributes and element names by using 

	StringBuilder sb = new StringBuilder();
	if (!s.substring(0, 1).matches("[a-zA-Z_]"))
	    throw new IllegalArgumentException();
	sb.append(s.substring(0, 1));
	for (int i = 1; i < s.length(); i++) {
	    if (s.substring(i, i + 1).matches("[a-zA-Z0-9_.-]")) {
		sb.append(s.substring(i, i + 1));
	    }
	}
	return sb.toString();

to sanitize shape feature attribute's values. Now attributes looks good but I am still getting the same exception. 

I am new to GIS and `org.geotools`.