By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,024 Members | 2,027 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,024 IT Pros & Developers. It's quick & easy.

Extra Lines inserted for Special Characters (&)

P: n/a
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[i]);
}
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 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
Jan 24 '07 #2

P: n/a


On Jan 24, 10:26 am, Joseph Kesselman <keshlam-nos...@comcast.net>
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 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.