Results 1 to 1 of 1
  1. #1
    fedekun is offline Member
    Join Date
    Dec 2010
    Rep Power

    Default 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

    Java Code:
    		<para>Welcome stranger!
    I must inform you of the evil which resides near this very little town
    		<para>You must leave, if you care about your safety! There are strange things happening...</para>
    		<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>
    And this is the handler

    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))
    				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.
    Last edited by fedekun; 12-29-2010 at 09:35 PM.

Similar Threads

  1. add a space after 10 lines?
    By ukemasta in forum New To Java
    Replies: 10
    Last Post: 01-20-2010, 01:12 PM
  2. Help explain the FOR lines please
    By hydride in forum New To Java
    Replies: 2
    Last Post: 01-20-2010, 12:52 AM
  3. Anyway to fix the lines so they dun shift?
    By PeterFeng in forum New To Java
    Replies: 0
    Last Post: 01-14-2009, 11:26 AM
  4. Random Lines
    By Urgle in forum New To Java
    Replies: 29
    Last Post: 11-12-2008, 04:42 PM
  5. how to edit lines.
    By jason27131 in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 05:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts