[Expat-discuss] [expat] newbie question

Nick MacDonald nickmacd at gmail.com
Mon Apr 9 05:18:21 CEST 2007


Jeffrey:

I think you need to make a new instance of the parser for each file.
What you are doing has the overall effect of concatenating the files
together one ofter the other, which would not be legal because there
can only be one main  XML element (my terminology may be off here) per
file.  Unfortunately I am not near a machine with my own code and not
on a machine that has (or can have) eXpat installed.  But in
pseudo-code, do this:

while (more files)
{
  parser=createParser()
  open(file)
  while(!eof)
  {
    read databuff
    xmlParse(databuff)
  }
  close(file)
  finalizeParser()
}

Good luck,
  Nick

On 4/8/07, Jeffrey Holle <jeffreyholle at bellsouth.net> wrote:
> I'm using expat 2.0.0 self build on Ubuntu Linux 5.10.
>
> The program that I'm writing needs to process N XML files.
> Note not nested, but in series.
>
> My first attempt initializes the expat parser and feeds the data into it
> like this (pseudo code):
>
> while(!files.eof())
> {
>    getline(files.filename);
>    ifstream file(filename);
>    do {
>      char buffer[256];
>      file.read(buffer,256);
>      XML_Parse(parser,buffer,file.gcount(),0);
>    } while (file.eof());
>    XML_Parse(parser,NULL,0,1);
> }
>
> I have not shown it, but I do have an element handler enabled and it
> works as expected for the first file, but not subsequent ones.
>
> What should I be doing to end one XML file parsing action and start another?
>
> _______________________________________________
> Expat-discuss mailing list
> Expat-discuss at libexpat.org
> http://mail.libexpat.org/mailman/listinfo/expat-discuss
>


-- 
Nick MacDonald
NickMacD at gmail.com


More information about the Expat-discuss mailing list