Extra Lines inserted for Special Characters (&)

Discussion in 'XML' started by lonni4000@swarmail.com, Jan 24, 2007.

  1. Guest

    My parser parses special characters okay, but adds extra line breaks.
    It makes no sense to me at all! If anyone knows what I am doing wrong,
    please help.

    text file:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE Feed SYSTEM "SDF_NA4.dtd">
    <Feed>
    .....
    <OfficialName>Great Big &amp; Little Co.</OfficialName>
    ........


    I use java SAXParserFactory (variable name = factory):
    factory.setValidating(true);

    and when I call convertElement(String) on this line, it reads it 3
    times!
    1st the code:
    public void convertElement(String elementValue) throws SAXException
    {
    if (eName.equals("OfficialName")) {
    company.setOfficalName(elementValue);
    tempCounter++;
    System.out.println("counter=" + tempCounter + " -->" +
    elementValue);
    char offName[] = elementValue.toCharArray();
    for (int i = 0; i < offName.length; i++) {
    System.out.println(offName);
    }
    2nd the output:
    <?xml version='1.0' encoding='UTF-8'?>counter=1 -->Great Big
    G
    r
    e
    a
    t

    B
    i
    g

    counter=2 -->&
    &
    counter=3 --> Little Co.

    L
    i
    t
    t
    l
    e

    C
    o
    ..


    Can anyone help!?

    Thank you
    Lonni
     
    , Jan 24, 2007
    #1
    1. Advertising

  2. Remember, SAX does not promise that all contiguous text will be
    delivered as a single call to characters() -- and entity references are
    one of many things which will cause it to be divided up.

    If you want a single contiguous string, your app is responsible for
    buffering the characters() events until it sees something else, and then
    processing the result.
     
    Joseph Kesselman, Jan 24, 2007
    #2
    1. Advertising

  3. Guest

    On Jan 24, 10:26 am, Joseph Kesselman <>
    wrote:
    > Remember, SAX does not promise that all contiguous text will be
    > delivered as a single call to characters()


    Thank you, I didn't realize that!

    I will change my code appropriately.

    Lonni
     
    , Jan 24, 2007
    #3
    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. Stefan Mueller
    Replies:
    3
    Views:
    33,307
    Stefan Mueller
    Jul 23, 2006
  2. Replies:
    2
    Views:
    1,139
    Ingo Menger
    May 31, 2007
  3. rvino
    Replies:
    0
    Views:
    4,720
    rvino
    Aug 14, 2007
  4. Paul D
    Replies:
    4
    Views:
    106
    Chris Mattern
    Jan 6, 2005
  5. majna
    Replies:
    4
    Views:
    777
    Thomas 'PointedEars' Lahn
    Sep 19, 2007
Loading...

Share This Page