[Expat-discuss] Text data handler

Shen, Lin lshen at cisco.com
Fri May 21 18:18:11 EDT 2004


I want to parse multiple documents one by one.
What I'm doing right now is to call XML_ParseCreate() once at the very beginning, and then call XML_Parse() for each document. I've tried setting the 4th parameter to both FALSE and TRUE, but always get "junk after document element at line" error when the second document gets fed into the parser.  

Thanks
Lin shen
Cisco Systems     

> -----Original Message-----
> From: expat-discuss-bounces at libexpat.org 
> [mailto:expat-discuss-bounces at libexpat.org] On Behalf Of Greg Martin
> Sent: Friday, May 21, 2004 1:45 PM
> To: expat-discuss at libexpat.org
> Subject: RE: [Expat-discuss] Text data handler
> 
> 
> 
> 
> > -----Original Message-----
> > From: expat-discuss-bounces at libexpat.org
> > [mailto:expat-discuss-bounces at libexpat.org]On Behalf Of 
> Thomás Inskip
> > Sent: Friday, May 21, 2004 2:29 PM
> > To: Karl Waclawek
> > Cc: expat-discuss at libexpat.org
> > Subject: Re: [Expat-discuss] Text data handler
> > 
> > 
> > It turns out the problem is very different, and I had made 
> an invalid
> > assumption.  There are two "outermost" xml elements being 
> parsed, one 
> > after the other.  The first one contains no element data (only 
> > attributes), but the second one does.  So I am dealing with 
> something 
> > that looks like:
> > 
> > <a>
> > <b attribute="value"></b>
> > </a>
> > <c>
> > <d>some text</d>
> > </c>
> > 
> > But without the linefeeds.  I had assumed that the problem
> > was that my 
> > text callback handler was the problem because I already 
> knew that my 
> > element start and end handlers were being called (for "a" and its 
> > sub-elements).
> > 
> > The manual says something about needing a separate parser for each
> > "document".  What is the exact definition of a document?  Is 
> > a document 
> > a data stream, or is the above two separate documents because 
> > there are 
> > two top-level elements (one defined by element a, and the 
> > other one by 
> > element d)?  Perhaps Expat was not meant to do what I am 
> asking it to 
> > do.
> > 
> 
> A couple of comments. First to your question ... a document 
> can only have 
> one top-level element. You should check the return value of 
> XML_Parse for 
> failure (I suspect it would have returned an error in your 
> case) and if 
> you are passing all your data in one pass the final parameter 
> of XML_Parse 
> should be true to indicate that it is your final call (or you 
> should make a
> final call to XML_Parse of length 0 and a fourth parameter == true).
> 
> 
> 
> _______________________________________________
> Expat-discuss mailing list
> Expat-discuss at libexpat.org
> http://mail.libexpat.org/mailman/listinfo/expat-discuss
> 



More information about the Expat-discuss mailing list