R
Raidri
Ambitioniertes Mitglied
- 1
Hey,
Folgendes Problem habe ich. Ich versuche diese Datensatz einzulesen
Funktioniert alles soweit, bis die umlaute kommen, wie bei dem namen "Möppel". Ich bekomme dann nur die Ausgabe "ppel".
Die Xml datei ist auf encoding="UTF-8"
Ich nutze den Saxparser mit nem Contenhandler. Nur wo ist mein Fehler ?
und hier der ContentHandler
Danke für die Hilfe
Folgendes Problem habe ich. Ich versuche diese Datensatz einzulesen
Code:
<customer>
<created-at type="datetime">2010-05-19T17:53:31+02:00</created-at>
<id type="integer">83555</id>
<name>Möppel</name>
<note>öööääää üüüü</note>
<updated-at type="datetime">2010-05-19T18:40:11+02:00</updated-at>
<archived type="boolean">false</archived>
</customer>
Die Xml datei ist auf encoding="UTF-8"
Ich nutze den Saxparser mit nem Contenhandler. Nur wo ist mein Fehler ?
Code:
this.get.setURI(new URI(this.getRootURL()+"customers.xml"));
this.get.addHeader("Content-Type", "text/xml; charset=UTF-8");
this.response = this.client.execute(get);
final ArrayList<Customer> customerList = new ArrayList<Customer>();
final HttpEntity entity = this.response.getEntity();
int statusCode = this.response.getStatusLine().getStatusCode();
if(statusCode == 200){
if(entity != null){
InputStream is = entity.getContent();
InputSource iso = new InputSource(is);
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader reader = sp.getXMLReader();
CustomerXMLHandler handler = new CustomerXMLHandler();
reader.setContentHandler(handler);
reader.parse(iso);
is.close();
sp.reset();
customerList.addAll(handler.getCustomers());
}
this.responder.setData(customerList);
this.responder.result();
}
Code:
@Override
public void characters(char ch[], int start, int length) {
if(this.id){
this.customer.setId(Integer.parseInt(new String(ch, start, length)));
}
else if(this.name){
this.customer.setName(new String(ch, start, length));
}
else if(this.note){
this.customer.setNote(new String(ch, start, length));
}
else if(this.archived){
this.customer.setArchived(Boolean.parseBoolean(new String(ch, start, length)));
}
else if(this.createdAt){
this.customer.setDate(new String(ch, start, length));
}
}