Results 1 to 1 of 1
Thread: SAX parsing new lines
- 12-29-2010, 08:30 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 1
- Rep Power
- 0
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
And this is the handlerJava 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>
stages is a ArrayList<ArrayList<String>> located in the main class.Java 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>(); } } }
The problem is that im having strings with only the first line of text.Last edited by fedekun; 12-29-2010 at 08:35 PM.
Similar Threads
-
add a space after 10 lines?
By ukemasta in forum New To JavaReplies: 10Last Post: 01-20-2010, 12:12 PM -
Help explain the FOR lines please
By hydride in forum New To JavaReplies: 2Last Post: 01-19-2010, 11:52 PM -
Anyway to fix the lines so they dun shift?
By PeterFeng in forum New To JavaReplies: 0Last Post: 01-14-2009, 10:26 AM -
Random Lines
By Urgle in forum New To JavaReplies: 29Last Post: 11-12-2008, 03:42 PM -
how to edit lines.
By jason27131 in forum New To JavaReplies: 1Last Post: 08-01-2007, 04:41 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks