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 Roberto Rigamonti <ro...@gmail.com> on 2008/08/07 14:13:10 UTC

Help using DOM entity resolver

Good afternoon, I'm always working on the same visor project and I have 
some troubles using the entity resolver mechanism. I've tried to 
understand its usage searching some examples with Google, but most of 
them concern a SAX parser, whereas I'm using a DOM parser. Looking in 
the mailing-list archives I've seen some posts on this argument, but 
they require the derivation of the XMLEntityResolver class and things 
like that, so they're far too complicated for my needs.
What I have to do is the following: I have a schema file in the 
executable's directory (e.g. /home/roby/3DVisor/sandbox/bin), let's call 
it "visor.xsd". Then I have some temporary XML files placed in the /tmp 
directory and created with the following header:

<visor xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="visor.xsd">

I have to "dynamically replace" the "visor.xsd" attribute in the XML 
file to the correct path of the schema file.
Is there a _simple_ way to do that? I've seen an example on
http://www.onlamp.com/pub/a/onlamp/2005/11/10/xerces_sax.html?page=3
that looks promising (the one using a SimpleEntityResolver), but regards 
a SAX parser. Is there a trick to force it to work also for a DOM parser?
Thanks in advance to anyone willing to help me.
                                       Roberto Rigamonti

Re: Help using DOM entity resolver

Posted by Roberto Rigamonti <ro...@gmail.com>.
I wasn't able to make the first method work, but the "Redirect method" 
works perfectly, thanks a lot!!!
				Roberto Rigamonti

Alberto Massari wrote:
> In this case you can just reuse the sample you found for SAX; use 
> XercesDOMParser::setEntityResolver to specify your 
> EntityResolver-derived object (like the SimpleEntityResolver you found). 
> If you want more informations about the entity you are requested to 
> return, you can instead use XercesDOMParser::setXMLEntityResolver and 
> use the same class defined in the Redirect sample, in 
> samples\Redirect\RedirectHandlers.hpp
> 
> Alberto
> 
> Roberto Rigamonti wrote:
>> No, I'm using XercesDOMParser, I've tried to "force" it working with a 
>> DOMEntityResolver but without results. Any other solution?
>> Thank you very much for your swift reply!
>>                             Roberto Rigamonti
>>
>> Alberto Massari wrote:
>>> If you are using DOMBuilder, you can use 
>>> DOMBuilder::setEntityResolver, specifying an instance of a class 
>>> derived from DOMEntityResolver.
>>> In that class, override
>>>    virtual DOMInputSource* resolveEntity
>>>    (
>>>        const   XMLCh* const    publicId
>>>        , const XMLCh* const    systemId
>>>        , const XMLCh* const    baseURI
>>>    ) = 0;
>>>
>>> returning a new Wrapper4InputSource(new 
>>> LocalFileInputSource("location of visor.xsd")) when sysntemId==visor.xsd
>>>
>>> Alberto
>>>
>>> Roberto Rigamonti wrote:
>>>> Good afternoon, I'm always working on the same visor project and I 
>>>> have some troubles using the entity resolver mechanism. I've tried 
>>>> to understand its usage searching some examples with Google, but 
>>>> most of them concern a SAX parser, whereas I'm using a DOM parser. 
>>>> Looking in the mailing-list archives I've seen some posts on this 
>>>> argument, but they require the derivation of the XMLEntityResolver 
>>>> class and things like that, so they're far too complicated for my 
>>>> needs.
>>>> What I have to do is the following: I have a schema file in the 
>>>> executable's directory (e.g. /home/roby/3DVisor/sandbox/bin), let's 
>>>> call it "visor.xsd". Then I have some temporary XML files placed in 
>>>> the /tmp directory and created with the following header:
>>>>
>>>> <visor xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>>        xsi:noNamespaceSchemaLocation="visor.xsd">
>>>>
>>>> I have to "dynamically replace" the "visor.xsd" attribute in the XML 
>>>> file to the correct path of the schema file.
>>>> Is there a _simple_ way to do that? I've seen an example on
>>>> http://www.onlamp.com/pub/a/onlamp/2005/11/10/xerces_sax.html?page=3
>>>> that looks promising (the one using a SimpleEntityResolver), but 
>>>> regards a SAX parser. Is there a trick to force it to work also for 
>>>> a DOM parser?
>>>> Thanks in advance to anyone willing to help me.
>>>>                                       Roberto Rigamonti
>>>>
>>>
>>>
>>
> 
> 

Re: Help using DOM entity resolver

Posted by Alberto Massari <am...@datadirect.com>.
In this case you can just reuse the sample you found for SAX; use 
XercesDOMParser::setEntityResolver to specify your 
EntityResolver-derived object (like the SimpleEntityResolver you found). 
If you want more informations about the entity you are requested to 
return, you can instead use XercesDOMParser::setXMLEntityResolver and 
use the same class defined in the Redirect sample, in 
samples\Redirect\RedirectHandlers.hpp

Alberto

Roberto Rigamonti wrote:
> No, I'm using XercesDOMParser, I've tried to "force" it working with a 
> DOMEntityResolver but without results. Any other solution?
> Thank you very much for your swift reply!
>                             Roberto Rigamonti
>
> Alberto Massari wrote:
>> If you are using DOMBuilder, you can use 
>> DOMBuilder::setEntityResolver, specifying an instance of a class 
>> derived from DOMEntityResolver.
>> In that class, override
>>    virtual DOMInputSource* resolveEntity
>>    (
>>        const   XMLCh* const    publicId
>>        , const XMLCh* const    systemId
>>        , const XMLCh* const    baseURI
>>    ) = 0;
>>
>> returning a new Wrapper4InputSource(new 
>> LocalFileInputSource("location of visor.xsd")) when sysntemId==visor.xsd
>>
>> Alberto
>>
>> Roberto Rigamonti wrote:
>>> Good afternoon, I'm always working on the same visor project and I 
>>> have some troubles using the entity resolver mechanism. I've tried 
>>> to understand its usage searching some examples with Google, but 
>>> most of them concern a SAX parser, whereas I'm using a DOM parser. 
>>> Looking in the mailing-list archives I've seen some posts on this 
>>> argument, but they require the derivation of the XMLEntityResolver 
>>> class and things like that, so they're far too complicated for my 
>>> needs.
>>> What I have to do is the following: I have a schema file in the 
>>> executable's directory (e.g. /home/roby/3DVisor/sandbox/bin), let's 
>>> call it "visor.xsd". Then I have some temporary XML files placed in 
>>> the /tmp directory and created with the following header:
>>>
>>> <visor xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>        xsi:noNamespaceSchemaLocation="visor.xsd">
>>>
>>> I have to "dynamically replace" the "visor.xsd" attribute in the XML 
>>> file to the correct path of the schema file.
>>> Is there a _simple_ way to do that? I've seen an example on
>>> http://www.onlamp.com/pub/a/onlamp/2005/11/10/xerces_sax.html?page=3
>>> that looks promising (the one using a SimpleEntityResolver), but 
>>> regards a SAX parser. Is there a trick to force it to work also for 
>>> a DOM parser?
>>> Thanks in advance to anyone willing to help me.
>>>                                       Roberto Rigamonti
>>>
>>
>>
>


Re: Help using DOM entity resolver

Posted by Roberto Rigamonti <ro...@gmail.com>.
No, I'm using XercesDOMParser, I've tried to "force" it working with a 
DOMEntityResolver but without results. Any other solution?
Thank you very much for your swift reply!
                             Roberto Rigamonti

Alberto Massari wrote:
> If you are using DOMBuilder, you can use DOMBuilder::setEntityResolver, 
> specifying an instance of a class derived from DOMEntityResolver.
> In that class, override
>    virtual DOMInputSource* resolveEntity
>    (
>        const   XMLCh* const    publicId
>        , const XMLCh* const    systemId
>        , const XMLCh* const    baseURI
>    ) = 0;
> 
> returning a new Wrapper4InputSource(new LocalFileInputSource("location 
> of visor.xsd")) when sysntemId==visor.xsd
> 
> Alberto
> 
> Roberto Rigamonti wrote:
>> Good afternoon, I'm always working on the same visor project and I 
>> have some troubles using the entity resolver mechanism. I've tried to 
>> understand its usage searching some examples with Google, but most of 
>> them concern a SAX parser, whereas I'm using a DOM parser. Looking in 
>> the mailing-list archives I've seen some posts on this argument, but 
>> they require the derivation of the XMLEntityResolver class and things 
>> like that, so they're far too complicated for my needs.
>> What I have to do is the following: I have a schema file in the 
>> executable's directory (e.g. /home/roby/3DVisor/sandbox/bin), let's 
>> call it "visor.xsd". Then I have some temporary XML files placed in 
>> the /tmp directory and created with the following header:
>>
>> <visor xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>        xsi:noNamespaceSchemaLocation="visor.xsd">
>>
>> I have to "dynamically replace" the "visor.xsd" attribute in the XML 
>> file to the correct path of the schema file.
>> Is there a _simple_ way to do that? I've seen an example on
>> http://www.onlamp.com/pub/a/onlamp/2005/11/10/xerces_sax.html?page=3
>> that looks promising (the one using a SimpleEntityResolver), but 
>> regards a SAX parser. Is there a trick to force it to work also for a 
>> DOM parser?
>> Thanks in advance to anyone willing to help me.
>>                                       Roberto Rigamonti
>>
> 
> 

Re: Help using DOM entity resolver

Posted by Alberto Massari <am...@datadirect.com>.
If you are using DOMBuilder, you can use DOMBuilder::setEntityResolver, 
specifying an instance of a class derived from DOMEntityResolver.
In that class, override
    virtual DOMInputSource* resolveEntity
    (
        const   XMLCh* const    publicId
        , const XMLCh* const    systemId
        , const XMLCh* const    baseURI
    ) = 0;

returning a new Wrapper4InputSource(new LocalFileInputSource("location 
of visor.xsd")) when sysntemId==visor.xsd

Alberto

Roberto Rigamonti wrote:
> Good afternoon, I'm always working on the same visor project and I 
> have some troubles using the entity resolver mechanism. I've tried to 
> understand its usage searching some examples with Google, but most of 
> them concern a SAX parser, whereas I'm using a DOM parser. Looking in 
> the mailing-list archives I've seen some posts on this argument, but 
> they require the derivation of the XMLEntityResolver class and things 
> like that, so they're far too complicated for my needs.
> What I have to do is the following: I have a schema file in the 
> executable's directory (e.g. /home/roby/3DVisor/sandbox/bin), let's 
> call it "visor.xsd". Then I have some temporary XML files placed in 
> the /tmp directory and created with the following header:
>
> <visor xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>        xsi:noNamespaceSchemaLocation="visor.xsd">
>
> I have to "dynamically replace" the "visor.xsd" attribute in the XML 
> file to the correct path of the schema file.
> Is there a _simple_ way to do that? I've seen an example on
> http://www.onlamp.com/pub/a/onlamp/2005/11/10/xerces_sax.html?page=3
> that looks promising (the one using a SimpleEntityResolver), but 
> regards a SAX parser. Is there a trick to force it to work also for a 
> DOM parser?
> Thanks in advance to anyone willing to help me.
>                                       Roberto Rigamonti
>