You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Bassem Srouji <Ba...@presagis.com> on 2009/05/09 01:15:47 UTC
GetLineNumber from
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
Thanks
--
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.
Re: GetLineNumber from
Posted by David Bertoni <db...@apache.org>.
Bassem Srouji wrote:
> 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?
I think the only way you can do this is to have your ContentHandler
derivative pass the Locator pointer to your XMLDocumentHandler derivate.
Dave
RE: GetLineNumber from
Posted by Bassem Srouji <Ba...@presagis.com>.
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:dbertoni@apache.org]
Sent: Saturday, May 09, 2009 3:23 PM
To: c-users@xerces.apache.org
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
RE: GetLineNumber from
Posted by Bassem Srouji <Ba...@presagis.com>.
Great, it's working
Thanks for your support
Regards
Bassem
-----Original Message-----
From: David Bertoni [mailto:dbertoni@apache.org]
Sent: Saturday, May 09, 2009 3:23 PM
To: c-users@xerces.apache.org
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
Re: GetLineNumber from
Posted by David Bertoni <db...@apache.org>.
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