Extra Lines inserted for Special Characters (&)

L

lonni4000

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
 
J

Joseph Kesselman

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.
 
L

lonni4000

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top