Hi

One more question.

How are we supposed to get the currently parsed line number from XMLDecl(...) 
method of an advanced handler class?
In v2.8 the advanced handlers do not have a setDocumentLocator() method, so the 
previously suggested solution that works just fine for normal handlers doesn't 
seem to apply to advanced ones!

And yeah, I know the xml declaration should be the first one in an XML file, 
but there can be an indefinite number of empty lines before the declaration 
itself...

Here's how I create my parser now (note the new installAdvDocHandler method 
call):

SAX2XMLReader* pParser = XMLReaderFactory::createXMLReader();
pParser->setContentHandler(MyOwnHandler);
pParser->setErrorHandler(MyOwnHandler);
pParser->setLexicalHandler(MyOwnHandler);
pParser->setEntityResolver(MyOwnHandler);

pParser->installAdvDocHandler(&MyAdvancedDocumentHandler);

and then I call the pParser->parse(MyFile.xml);

Any idea?


Thanks
Bassem


--
Bassem Srouji
Sr. Software Developer | Presagis

T. +1 514 341.3874 X322  F. +1 514 341.8018

DISCLAIMER: This e-mail message is for the sole use of the intended 
recipient(s) and may contain confidential and/or proprietary information. Do 
not read, copy, or disseminate this message unless you are the addressee. Any 
unauthorized review, use, disclosure or distribution is strictly prohibited. If 
you have received this message in error, please contact the sender by reply 
e-mail and delete the original and any copies from your system.

AVERTISSEMENT : Ce courriel s’adresse exclusivement au(x) destinataire(s) 
mentionné(s) et peut contenir de l’information confidentielle et/ou de nature 
exclusive. Ne pas lire, copier ou transmettre à quiconque ce courriel sauf si 
vous en êtes le destinataire. Il est strictement interdit de réviser, utiliser, 
transmettre ou distribuer ce courriel sans autorisation préalable. Si vous avez 
reçu ce message par erreur, veuillez communiquer avec l’expéditeur en répondant 
à ce courriel et en supprimant le courriel original et toutes les copies 
enregistrées sur votre système.

-----Original Message-----

From: David Bertoni [mailto:[email protected]]
Sent: Saturday, May 09, 2009 3:23 PM
To: [email protected]
Subject: Re: GetLineNumber from

Bassem Srouji wrote:
> Hi,
>
> I am using xerces 2.8.0
> I create my parser like that:
>
> SAX2XMLReader* pParser = XMLReaderFactory::createXMLReader();
> pParser->setContentHandler(MyOwnHandler);
> pParser->setErrorHandler(MyOwnHandler);
> pParser->setLexicalHandler(MyOwnHandler);
> pParser->setEntityResolver(MyOwnHandler);
>
> and then I call the pParser->parse(MyFile.xml);
>
> Now, I want to get the line number of the element that is being parsed from 
> the MyOwnHandler::startElement function
>
> I am not able to figure out how to get to the getLineNumber function of 
> parser from my SAX2XMLReader object
Well, you could pass a pointer to the parser to your handler, but
SAX2XMLReader does not have a getLineNumber() member function.

The standard way to do this is to override setDocumentLocator() function
in your ContentHandler, then save the Locator pointer.  At any point
during a parse, you can call member functions of the Locator instance to
get line number information.

Dave

Reply via email to