Following code would do what you want

EsXml4cDomEntityResolver* entHandler = new EsXml4cDomEntityResolver();

parserInstance_->setEntityResolver(entHandler);

// EsXml4cDomEntityResolver.h: interface for the EsXml4cDomEntityResolver
class.
//
//////////////////////////////////////////////////////////////////////

#if
!defined(AFX_ESXML4CDOMENTITYRESOLVER_H__914F4A38_1ECD_4439_A9AB_9D141BACE4F
4__INCLUDED_)
#define
AFX_ESXML4CDOMENTITYRESOLVER_H__914F4A38_1ECD_4439_A9AB_9D141BACE4F4__INCLUD
ED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


#ifdef WIN32
#include <windows.h>
#include <process.h>
#else
#include <pthread.h>
#endif

#include "EsLogger.h"
#include "EsXMLCh.h"
#include "treeString.h"


#include <xercesc/dom/DOMEntityResolver.hpp>
#include <xercesc/framework/LocalFileInputSource.hpp>

#define HANDLE_EXCEPTION(statement) \
  try { \
    statement; \
  } \
  catch (const XMLException& e) { \
        ESLOG(LOG_FATAL,"%s,%d:%s\n",__FILE__,__LINE__,e.getMessage()); \
        throw; \
  } \
  catch (DOMException& e) { \
        ESLOG(LOG_FATAL,"%s,%d:%d %s\n",__FILE__,__LINE__,e.code,e.msg); \
        throw; \
  } \
  catch (...) { \
        ESLOG(LOG_FATAL,"%s,%d:%d
%s\n",__FILE__,__LINE__,ET_Unspecified,"Unknown exception"); \
        throw; \
  }

#define HANDLE_EXCEPTION_EXT(pre_statements, statements, post_statements) \
  try { \
    pre_statements; \
    HANDLE_EXCEPTION(statements); \
    post_statements; \
  } \
  catch (cException&) { \
    post_statements; \
    throw; \
  } \
  catch (...) { \
    ESLOG(LOG_FATAL,"%s,%d:%d
%s\n",__FILE__,__LINE__,ET_Unspecified,"Unknown exception"); \
        throw; \
  }

XERCES_CPP_NAMESPACE_USE

class EsXml4cDomEntityResolver : public DOMEntityResolver  
{
public:
        EsXml4cDomEntityResolver();
        virtual ~EsXml4cDomEntityResolver();
        void addEntity(const char* publicId, const char* systemId, const
char* xmldocument);
        void addDirToPath(const char* pzDir);
        void addDirToPath(const treeString& pzDir);
        DOMInputSource* resolveEntity(const XMLCh* const publicId, const
XMLCh* const systemId, const XMLCh* const baseURI);

private:
        const static treeString unixenvsep_, winenvsep_, unixpathsep_,
winpathsep_;
        struct EsdEntity
        {
                EsdEntity* psNext;
                EsXMLCh publicId;
                EsXMLCh systemId;
                EsXMLCh document;
        };
#ifdef WIN32
                CRITICAL_SECTION sMutex;
#else
                pthread_mutex_t sMutex;
#endif

        EsdEntity* m_psHead;
        char* m_pzPath;
        treeStringList dirs_;
};
//XERCES_CPP_NAMESPACE_END
#endif //
!defined(AFX_ESXML4CDOMENTITYRESOLVER_H__914F4A38_1ECD_4439_A9AB_9D141BACE4F
4__INCLUDED_)


DOMInputSource* EsXml4cDomEntityResolver::resolveEntity(const XMLCh* const
publicId, const XMLCh* const systemId, const XMLCh* const baseURI)
{
// here you can replace the passed dtd with the one you want.
        InputSource* result = NULL;

        printf("publicId=%ws\n", publicId);
        printf("systemId=%ws\n", systemId);
        printf("baseURI=%ws\n", baseURI);

    try
        {
        //EnterCriticalSection(&sMutex);
        //{
        // Loop through list searching for entity
        EsdEntity* psLoop = m_psHead;
        bool bFound = false;

        while (!bFound && psLoop)
                {
                        if (psLoop->publicId == publicId && psLoop->systemId
== systemId)
                                bFound = true;
                        else
                                psLoop = psLoop->psNext;
        }

        if (bFound)
                {
                        //result = new MemBufInputSource((const
XMLByte*)(const char*)psLoop->document,
        
//psLoop->document.getLength(), "xmldocument", false);
        }
        //}

                if (!result)
                { // Not found in list, search in path
                        char* pzLoop = m_pzPath;

                        while (!result && pzLoop)
                        {
                                // Fetch next dir from path
                                char* pzEnd = strchr(pzLoop,
envsep_.c_str()[0]);

                                if (pzEnd) *pzEnd = '\0';
                                treeString oPath(pzLoop);
                                if (oPath.c_str()[oPath.length()-1] !=
pathsep_.c_str()[0])
                                        oPath += pathsep_;
                                if (pzEnd) *pzEnd = ';';

                                LocalFileInputSource* fileinput = NULL;
                                try
                                {
                                        DOMString tmp(oPath.c_str());
                                        fileinput = new
LocalFileInputSource(tmp.rawBuffer(), systemId);
                                        std::ifstream in;
        
in.open(EsXMLCh(fileinput->getSystemId()).c_str());
                                        if (in.is_open())
                                          result = fileinput;
                                        else
                                          delete fileinput;
                                }
                                catch (...)
                                {
                                        delete fileinput;
                                        result = NULL;
                                }

                                if (pzEnd)
                                        pzLoop = pzEnd+1;
                                else
                                        pzLoop = NULL;
                        }
                }
/*
                if (!result)
                { // Not found in path, search in resources
                        byte* pbBuffer = NULL;
                        cResource oDTDResource;

                        try
                        {
                                oDTDResource.Select("DTD", cString('"') <<
(const char*)cDOMString(systemId) << '"');
                                int nBufferLen = oDTDResource.Get(pbBuffer);
                                result = new MemBufInputSource((const
XMLByte*) pbBuffer, nBufferLen, "xmldocument", true);
                        }
                        catch (cException&)
                        {
                                delete pbBuffer;
                        }
                }
*/
        //LeaveCriticalSection(&sMutex);
        }
    catch (const XMLException& e)
        {
                //LeaveCriticalSection(&sMutex);
        
ESLOG(LOG_FATAL,"%s,%d:%s\n",__FILE__,__LINE__,e.getMessage());
                throw;
    }
        catch (const DOMException& e)
        {
                //LeaveCriticalSection(&sMutex);
                ESLOG(LOG_FATAL,"%s,%d:%d
%s\n",__FILE__,__LINE__,e.code,e.msg);
                throw;
    }
    catch (...)
        {
                ESLOG(LOG_FATAL,"%s,%d:%d
%s\n",__FILE__,__LINE__,-1,"Unknown exception");
                throw;// cException("Unknown exception", -1, ET_Unspecified,
__FILE__, __LINE__);
    }

        return new Wrapper4InputSource(result);
}

-----Original Message-----
From: Andreas B. Thun [mailto:[EMAIL PROTECTED]
Sent: 29 August 2003 08:04
To: [EMAIL PROTECTED]
Subject: Validation with another DTD than specified in XML file


Hello!

We had this before, but still no solution.
Anyone know nows how to override the DTD?

Andi

>Is there a way to force the DOMParser to validate
>a DTD which is different to the DTD specified
>in the XML file?
>
><?xml version="1.0" encoding="UTF-8"?>
><!DOCTYPE ConstraintTypes SYSTEM "constraint_template.dtd">
>                                     ^^^^^^^^^^^^^^^
>                                     want to use another one


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to