Xerces parsing losing data...

  • Thread starter trent ohannessian
  • Start date
T

trent ohannessian

Hello -

I'm using the Xerces parser to parse a small XML file. I've noticed
that randomly the XML parsing process would chop off the first N
characters of a given element's value. It's always the same element,
but not every time, and it's always chopping off the same number of
characters.

For example, I have an <shipping_address2></shipping_address2>
element. Nine times out of ten it will parse correctly. But the
other time it will cut off the first half of the value. This
particular XML file has 132 transactions in it, so around 13 will have
this problem.

Has anyone seen this before? Any ideas?

Thanks,
Trent
 
S

Steve Jasper

This is a common gotcha....

I assume you're using the following method:

characters(char[] ch, int start,int length)

to get the characters of an element. Xerces will sometimes make
multiple calls to this method for a particular element, effectively
breaking the element data into chunks. What you are experiencing is
that sometimes the element is broken up into only one chunk (so it
looks like it works). In other cases, it's broken up into multiple
chunks, and I bet you're only getting the first chunk.


You need to keep a local variable that holds this data from each call
within an element to this method, making sure to keep appending to
this local variable until the endElement callback is called. Then
you'll know you have the entire element.

good luck.
 
T

trent ohannessian

That worked perfectly. Thank you very much!

Trent

This is a common gotcha....

I assume you're using the following method:

characters(char[] ch, int start,int length)

to get the characters of an element. Xerces will sometimes make
multiple calls to this method for a particular element, effectively
breaking the element data into chunks. What you are experiencing is
that sometimes the element is broken up into only one chunk (so it
looks like it works). In other cases, it's broken up into multiple
chunks, and I bet you're only getting the first chunk.


You need to keep a local variable that holds this data from each call
within an element to this method, making sure to keep appending to
this local variable until the endElement callback is called. Then
you'll know you have the entire element.

good luck.



Hello -

I'm using the Xerces parser to parse a small XML file. I've noticed
that randomly the XML parsing process would chop off the first N
characters of a given element's value. It's always the same element,
but not every time, and it's always chopping off the same number of
characters.

For example, I have an <shipping_address2></shipping_address2>
element. Nine times out of ten it will parse correctly. But the
other time it will cut off the first half of the value. This
particular XML file has 132 transactions in it, so around 13 will have
this problem.

Has anyone seen this before? Any ideas?

Thanks,
Trent
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top