Problem with characters() method in java SAX DefaultHandler

Discussion in 'Java' started by Wes Batson, Feb 6, 2004.

  1. Wes Batson

    Wes Batson Guest

    I am trying to parse data from the following xml file:

    <?xml version+"1.0"?>
    <Data>
    <coName>Company Name</coName>
    <coAdd>Company Address</coAdd>
    </Data>

    Here is my characters() method:

    public void characters(char[] ch, int start, int length) throws
    SAXException{
    stringarray[position] = new String(ch, start, length);
    }

    Later I print out the stringarray. I have seen in every example that
    overriding the characters() method should grab the data inside the
    tags. However, I have noticed that when characters() is called each
    time the char[] ch is an empty string. I was curious if anyone has
    had this problem before.

    Thanks in advance,

    WWB
    Wes Batson, Feb 6, 2004
    #1
    1. Advertising

  2. On Fri, 06 Feb 2004 09:02:16 -0800, Wes Batson wrote:

    > I am trying to parse data from the following xml file:
    >
    > <?xml version+"1.0"?>
    > <Data>
    > <coName>Company Name</coName>
    > <coAdd>Company Address</coAdd>
    > </Data>
    >
    > Here is my characters() method:
    >
    > public void characters(char[] ch, int start, int length) throws
    > SAXException{
    > stringarray[position] = new String(ch, start, length);
    > }
    > }


    FYI, a single call to characters may or may not contain all the characters
    between tags. Many parsers use a StringBuffer then Stringify it when the
    tag is closed.

    La'ie Techie
    =?UTF-8?b?TMSByrtpZSBUZWNoaWU=?=, Feb 7, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. YuliaG
    Replies:
    2
    Views:
    444
    Arnaud Berger
    Apr 4, 2005
  2. leo
    Replies:
    1
    Views:
    625
    Adam Maass
    Apr 13, 2005
  3. Replies:
    2
    Views:
    602
    Sylvain Loiseau
    Aug 5, 2006
  4. Replies:
    2
    Views:
    692
    Joseph Kesselman
    Apr 17, 2007
  5. shivaraj
    Replies:
    3
    Views:
    1,325
    shivaraj
    Jul 7, 2008
Loading...

Share This Page