[Expat-discuss] Run-time error during file parsing

Karl Waclawek karl at waclawek.net
Mon Nov 22 19:59:10 CET 2004


> Hello,I have small xml file that I want to parse into my application :
> 
> <layout numOfFloors="1">
> <floor floorNo="0">
> <room>0LVRM</room>
> <room>0COR1</room>
> <room>0DNRM</room>
> </floor>
> </layout>
> 
> For each element I want to do different things so my start element handler
> is of the form
> 
> if(strcmp(el,"layout")==0)
> {
>   .....
> }
> 
> if(strcmp(el,"floor")==0
> {
>   ....
> }
> 
> Now I get a number of strange parsing errors....I did a number of tests and
> I've discovered the following:the <layout> and <floor> start tags seem to be
> recognised ok. However,my character handler is called EVERY time-even though
> <layout> and <floor> don't contain any characters.Shouldn't the character
> handler only be called when a <room> element tag is being parsed?

You have line breaks, which are character data! So the handler must be called.
 
> Also,I've discovered that the string that gets copied by the character
> handler actually contains not only the character data,but the end tag as
> well-so instead of having  0LVRM being parsed I get 0LVRM</room>. I guess
> that the run time error is the result of both of these anomalies but I can't
> see why they take place..

Are you sure you are copying only the number of characters indicated
by the "len" argument passed to the handler?

Karl


More information about the Expat-discuss mailing list