You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Bala Ayres <ba...@XSeLlence.com> on 2000/09/11 04:00:04 UTC

Using multiple instance of parser

I wonder if anyone out there know why this is happening - if it is a
problem that was recorded earlier - please point me to that.

Creating DTDValidator object and SAXParser object in two separate
functions in a linux based C/C++ program causes memory fault...

The code fragments are shown below.

Thanks

Bala Ayres
XSeLLENCE Inc

Dean Roddey wrote:

> The parser adopts the validator. You must create a new one for each new
> parser instance.

Ok - and the code creates new Validator instance for each new parser
instance...The platform is Linux - and still no luck.

Bala Ayres
XSeLLENCE Inc


>
>
> --------------------------
> Dean Roddey
> The CIDLib C++ Frameworks
> Charmed Quark Software
> droddey@charmedquark.com
> http://www.charmedquark.com
>
> "It takes two buttocks to make friction"
>     - African Proverb
>
> ----- Original Message -----
> From: "Bala Ayres" <ba...@XSeLlence.com>
> To: <xe...@xml.apache.org>
> Sent: Saturday, September 09, 2000 3:31 PM
> Subject: Multiple use of DTDValidator and SAXParser causes memory fault
>
> > The code snippet :
> >
> >  DTDValidator *valTouse
> >  valToUse = new DTDValidator;
> > SAXParser::ValSchemes valScheme = SAXParser::Val_Auto ;
> > ......
> > .......
> > .......
> >
> > SAXParser parser(valToUse);
> > parser.serValidationScheme(valScheme) ;
> > ......more code
> > ......
> >
> > This snippet included first time in a function called xmlmain() works
> > fine.
> > But creating yet another function say xmlmain2() with exact same
> > construct
> > causes memory fault at SAXParser parser(valToUse);
> >
> > Question: Is it not possible to create as many instances of the parser
> > as needed in different parts of the program ?? Should only one instance
> > of the parser be used to do all the work?
> >
> > TIA
> >
> > Bala Ayres
> > XSeLLENCE Inc
> >
> >

RE: Using multiple instance of parser

Posted by Radovan Chytracek <Ra...@cern.ch>.
Hi,

       I don't use two functions instead I have two classes in my application.
The both inherit from
HandlerBase class. The first use SAX in batch to eat the whole XML file and is
the document handler registered
by the SAXParser instance created in the main(). The second class uses SAX
parser internally and for its instance of
the SAXParser it registers itself as a document handler. It runs in the
progressive parsing mode to look for
a given tag, actually resolves and checks 'HREF' links across many XML files.
The scenario is that whenever
the former gets a hyperlink it creates an instance of the latter and let it
perform the check of that reference.
Thus two parsers work at the same time. Well, the first one is postponed until
its resolver fellow finishes its job.
Not very efficient but works :-))

If you want to have a look at the sources go to:
http://cern.ch/chytrace/hepmaterials/readme.html and look for
a link containing source distribution. This little quick hack application
works on Windows/NT and on Linux too.


The best regards
                    Radovan Chytracek

--
Radovan Chytracek                     LHCb experiment at CERN
e-mail: Radovan.Chytracek@cern.ch     WWW: http://home.cern.ch/~chytrace
phone:  +41 22 76 72486

> > > The code snippet :
> > >
> > >  DTDValidator *valTouse
> > >  valToUse = new DTDValidator;
> > > SAXParser::ValSchemes valScheme = SAXParser::Val_Auto ;
> > > ......
> > > .......
> > > .......
> > >
> > > SAXParser parser(valToUse);
> > > parser.serValidationScheme(valScheme) ;
> > > ......more code
> > > ......
> > >
> > > This snippet included first time in a function called xmlmain() works
> > > fine.
> > > But creating yet another function say xmlmain2() with exact same
> > > construct
> > > causes memory fault at SAXParser parser(valToUse);
> > >
> > > Question: Is it not possible to create as many instances of the parser
> > > as needed in different parts of the program ?? Should only one instance
> > > of the parser be used to do all the work?
> > >
> > > TIA
> > >
> > > Bala Ayres
> > > XSeLLENCE Inc
> > >
> > >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>
>