473,804 Members | 3,446 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.isWhi tespace(chars[start]) )
{
++start;
--length;
}
while ( (length 0) &&
Character.isWhi tespace(chars[start+length-1]) ) {
--length;
}
if ( length 0 ) {
_text += new String(chars,st art,length);
}
}

Aug 2 '06 #1
2 1522
* 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****@h oehrmann.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.isWhi tespace(chars[start]) )
{
++start;
--length;
}
while ( (length 0) &&
Character.isWhi tespace(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,st art,length);
}
}
Concatenation is dangerous for performance. You may consider using a
StringBuffer (sb.append(char s, start, length)).
Aug 5 '06 #3

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

Similar topics

7
6220
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 make it better soon. Unfortunately, there is never a non-crucial time in which we can do an upgrade, so we are stuck for now. Point 1: There are multiple tables: students, courses, cross-reference
32
14917
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 ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
5
1504
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 DoBatchWork.aspx is: <%@ Page language="c#" EnableViewState="false" ContentType="text/html" %> <script language="C#" runat="server">
15
6634
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 a single method to a delegate in VB.NET. I want to use it as in C#... to fire multiple events. Thanks in advance!
33
1022
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 (checks omitted) char tst = "this\nis\n\nan\nempty\n\n\nline"; ^^^^ ^^^^^^ char *tok = strtok(tst, "\n");
9
4104
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 puts() to print to screen ????
92
4783
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 have a form where you can add and delete multiple serial information. This works wonderful. But now for every serial information i add i need to be able to add and remove multiple parts to that serial. heres an example of what i mean serial...
58
8147
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 the parts section an i seem to be having trouble. When i try to insert into the parts section i get the error Invalid character value for cast specification. But not sure what i am doing wrong. Here is what i am using to insert. All the sections...
482
28031
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. what i am trying to display previously entered multiple fields. I am able to get my serial fields to display correctly, but i can not display my parts fields correctly. Currently this is what it does serial information 1 parts 1
0
9585
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10586
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10082
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7622
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6856
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5658
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3823
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.