473,327 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

SAX multiple calls to characters()

I am using the function listed below to handle characters events in
SAX. It does not handle multiple sequential calls to this function
correctly. For example, I am getting
"2 4 816 32 64" as a value for an element when processing <vec2 4 8
16 32 64 </vec>
because I am getting 2 calls to process the text in this element, one
for "2 4 8" and the other for "16 32 64". I have tried appending a
blank to the result after each call to this function, but that
sometimes splits numbers or words, depending on what is passed to this
function.

Is there a better way of handling multiple characters events? Thanks

public void characters(char[] chars, int start, int length) {
while ( (length 0) && Character.isWhitespace(chars[start]) )
{
++start;
--length;
}
while ( (length 0) &&
Character.isWhitespace(chars[start+length-1]) ) {
--length;
}
if ( length 0 ) {
_text += new String(chars,start,length);
}
}

Aug 2 '06 #1
2 1502
* me*****@rsn.hp.com wrote in comp.text.xml:
>I am using the function listed below to handle characters events in
SAX. It does not handle multiple sequential calls to this function
correctly.
Then you need to change that. It is normal for SAX processors to call
the characters() callback multiple times, you have to design your code
so it can handle that. One option here is to simply buffer the data and
process it when all data has been accumulated (e.g., when the endElement
callback is called).
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Aug 3 '06 #2
Le 02-08-2006, me*****@rsn.hp.com <me*****@rsn.hp.coma écrit*:
I am using the function listed below to handle characters events in
SAX. It does not handle multiple sequential calls to this function
correctly.
For example, I am getting
"2 4 816 32 64" as a value for an element when processing <vec2 4 8
16 32 64 </vec>
because I am getting 2 calls to process the text in this element, one
for "2 4 8" and the other for "16 32 64".
The expected behavior of a SAX API preserve all characters, whitespaces
included, of the input document. Your problem is either in your code, either
(less probably ;-)) in the SAX implementation you used.
I have tried appending a
blank to the result after each call to this function, but that
sometimes splits numbers or words, depending on what is passed to this
function.
I think this is definitly not the good solution :-)
Is there a better way of handling multiple characters events? Thanks
public void characters(char[] chars, int start, int length) {
while ( (length 0) && Character.isWhitespace(chars[start]) )
{
++start;
--length;
}
while ( (length 0) &&
Character.isWhitespace(chars[start+length-1]) ) {
--length;
}
This is this piece of code, as far as I understand, which is responsible for
the behaviour you complain about! You remove the trailling whitespace
characters in the characters chunks you receive, so how can you expect to see
the whitespace characters in the outputed string?
if ( length 0 ) {
_text += new String(chars,start,length);
}
}
Concatenation is dangerous for performance. You may consider using a
StringBuffer (sb.append(chars, start, length)).
Aug 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Rick Caborn | last post by:
Does anyone know of a way to execute sql code from a dynamically built text field? Before beginning, let me state that I know this db architecture is built solely for frustration and I hope to...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
5
by: Mark Fox | last post by:
Hello, I have a page DoBatchWork.aspx that my web host's cron requests periodically. It currently calls another web page that does some batch processing. The code I am currently using in...
15
by: Iced Crow | last post by:
In C# I know that you can use delegates to assing multiple addresses of sub and functions to a delegate and have it fire multiple procedures... How do I do this in VB? I only know of assigning...
33
by: Geometer | last post by:
Hello, and good whatever daytime is at your place.. please can somebody tell me, what the standard behavior of strtok shall be, if it encounters two or more consecutive delimiters like in...
9
by: anon.asdf | last post by:
In terms of efficieny: Is it better to use multiple putchar()'s after one another as one gets to new char's OR is it better to collect the characters to a char-array first, and then use...
92
by: bonneylake | last post by:
Hey Everyone, Well i was hoping someone could explain the best way i could go about this. i have a few ideas on how i could go about this but i am just not sure if it would work. Right now i...
58
by: bonneylake | last post by:
Hey Everyone, Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple fields for the not only the serial section but also...
482
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if this is more of a coldfusion problem or a javscript problem. So if i asked my question in the wrong section let me know an all move it to the correct place. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.