Je suis actuellement en utilisant SAXParser avec SAXParserFactory, et j'ai rencontré un problème avec les chaînes étant coupé à '&' symboles. Par exemple: "Nation a créé notre monde &" tout devient "tout".SAXParser '&' problème de concaténation
Évidemment, je ne veux pas que cela arrive. Dans l'entrée xml, le caractère est correctement échappé sous la forme &
. Comment puis-je résoudre ça?
try{
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
/* Get the XMLReader of the SAXParser we created. */
XMLReader r = sp.getXMLReader();
//This handles the xml and populates the entries array
XMLHandler handler = new XMLHandler();
// register event handlers
r.setContentHandler(handler);
String url = "http://foobar.xml";
r.parse(url);
return handler.getEntries();
}
J'ai dans ma classe DefaultHandler
....
public void characters(char ch[], int start, int length){
String value = new String(ch , start , length);
if(!value.trim().equals("")) {
if(currentElement.equalsIgnoreCase("TITLE")) {
tempEntry.setTitle(value);
}
....
mon erreur, mais il est «Nation créé notre monde tout en & ce dans le fichier XML. Je vais essayer ce que vous avez suggéré –
merci, cela a fonctionné –