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 mo...@factset.com on 2000/12/26 20:59:19 UTC

SAX Locator

Is there a simple example of an implementation of the Locator?  I was
looking at the ReaderMgr, which is the only class I could find that
inherited from the Locator.  However, it seemed to have a great deal of
extra functionality that would not be required by a class that was just
implementing the Locator.  Any assitance here would be greatly appreciated.

Thanks,
Marcus C. Oladell
Factset Research Systems


Re: SAX Locator

Posted by Dean Roddey <dr...@charmedquark.com>.
That's not really correct, though it will work technically. The SAX
DocumentHandler interface provides a callback via which the parse gives you
a pointer to the locator object. You store that pointer and use it until the
document ends. The next time, you might get a completely different object.
This is the portable SAX way of doing it.

--------------------------
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: "Jim Cole" <jc...@tecomac.com>
To: <xe...@xml.apache.org>
Sent: Tuesday, January 02, 2001 1:51 PM
Subject: Re: SAX Locator


> >'you are passed a pointer'  through which function call?
> >
>
> Hi - I don't know if it is the *right* way to do things, but I did the
> following to get a Locator.
>
> SAXParser parser;
>
> const Locator* posLocator = (parser.getScanner()).getLocator();
>
> This seems to work.
>



Re: SAX Locator

Posted by Jim Cole <jc...@tecomac.com>.
ruud waij's bits of Tue, 2 Jan 2001 translated to:

>Dean Roddey wrote:
>
>> At the start of each SAX parse, you are passed a pointer to an object that
>> implements the Locator interface. You don't own it, you just get to use it
>> for the length of the parse. That object can implement anything it wants,
>> but you only see it as a Locator. Don't assume its anything else, or try to
>> cast it to what you think it might really be.
>>
>
>'you are passed a pointer'  through which function call?
>

Hi - I don't know if it is the *right* way to do things, but I did the
following to get a Locator.

SAXParser parser;

const Locator* posLocator = (parser.getScanner()).getLocator();

This seems to work.


Jim


Re: SAX Locator

Posted by ruud waij <wa...@wt.tno.nl>.
Dean Roddey wrote:

> At the start of each SAX parse, you are passed a pointer to an object that
> implements the Locator interface. You don't own it, you just get to use it
> for the length of the parse. That object can implement anything it wants,
> but you only see it as a Locator. Don't assume its anything else, or try to
> cast it to what you think it might really be.
>

'you are passed a pointer'  through which function call?

The only function I could find is:

               void DocumentHandler::setDocumentLocator (
                                                    const Locator * const
                                                    locator ) [pure
                                                    virtual]

                Receive an object for locating the origin of SAX document
events. ...

To this function you would have to pass an &locator which you instantiated
yourself. This of course is not possible because class Locator is pure virtual.
Besides, the Locator parameter above is heavily 'const'ed.

Which SAX interface function returns the Locator pointer?

ruud


Re: SAX Locator

Posted by Dean Roddey <dr...@charmedquark.com>.
At the start of each SAX parse, you are passed a pointer to an object that
implements the Locator interface. You don't own it, you just get to use it
for the length of the parse. That object can implement anything it wants,
but you only see it as a Locator. Don't assume its anything else, or try to
cast it to what you think it might really be.

So just store away the pointer when you are given it, and use it during the
SAX callbacks to find out location information. At the end of the parse,
just clear out the pointer to make sure you don't accidentally use it before
the next parse happens.

--------------------------
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: <mo...@factset.com>
To: <xe...@xml.apache.org>
Sent: Tuesday, December 26, 2000 11:59 AM
Subject: SAX Locator


> Is there a simple example of an implementation of the Locator?  I was
> looking at the ReaderMgr, which is the only class I could find that
> inherited from the Locator.  However, it seemed to have a great deal of
> extra functionality that would not be required by a class that was just
> implementing the Locator.  Any assitance here would be greatly
appreciated.
>
> Thanks,
> Marcus C. Oladell
> Factset Research Systems
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>