-
SAX parsing new lines
Hi all! I'm having problems with parsing this XML with sax, as it has new lines and my code just seems to ignore them, it only reads the first line.
This is the XML i use to test my code
Code:
<npc>
<stage>
<para>Welcome stranger!
I must inform you of the evil which resides near this very little town
</para>
<para>You must leave, if you care about your safety! There are strange things happening...</para>
</stage>
<stage>
<para>Oh my god! You have the stone... Quickly, go to Manson Mansion</para>
<para>You will know what to do once you get there!</para>
</stage>
</npc>
And this is the handler
Code:
private class NpcXmlParser extends DefaultHandler {
private boolean para = false;
private boolean stage = false;
private ArrayList<String> arrPara;
public void startDocument() throws SAXException {
stages = new ArrayList<ArrayList<String>>();
arrPara = null;
}
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
if (qName.equalsIgnoreCase("stage"))
stage = true;
if (qName.equalsIgnoreCase("para"))
para = true;
}
public void characters(char ch[], int start, int length)
throws SAXException {
if (para) {
para = false;
arrPara.add(new String(ch, start, length));
}
if (stage) {
stage = false;
if (!(arrPara == null))
stages.add(arrPara);
arrPara = new ArrayList<String>();
}
}
}
stages is a ArrayList<ArrayList<String>> located in the main class.
The problem is that im having strings with only the first line of text.