2004-06-03 15:00:19 +02:00
|
|
|
/*
|
2005-08-12 19:06:53 +02:00
|
|
|
XML.h - Xerces wrappers & convenience functions
|
2004-06-03 15:00:19 +02:00
|
|
|
|
|
|
|
AUTHOR : Simon Brenner <simon@wildfiregames.com>, <simon.brenner@home.se>
|
|
|
|
EXAMPLE :
|
|
|
|
Simple usage:
|
|
|
|
|
|
|
|
CVFSEntityResolver *entRes=new CVFSEntityResolver(filename);
|
|
|
|
parser->setEntityResolver(entRes);
|
|
|
|
|
|
|
|
CVFSInputSource src;
|
|
|
|
if (src.OpenFile("this/is/a/vfs/path.xml")==0)
|
|
|
|
parser->parse(src);
|
|
|
|
|
|
|
|
delete entRes;
|
|
|
|
|
|
|
|
The input source object should be kept alive as long as the parser is
|
|
|
|
using its input stream (i.e. until the parse is complete). The same
|
|
|
|
goes for the entity resolver.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _XercesVFS_H
|
|
|
|
#define _XercesVFS_H
|
|
|
|
|
2004-07-08 17:22:09 +02:00
|
|
|
// Temporarily undefine new, because the Xerces headers don't like it
|
2005-08-09 17:55:44 +02:00
|
|
|
#include "nommgr.h"
|
|
|
|
|
|
|
|
// temporarily go down to W3 because Xerces (in addition to all its other
|
|
|
|
// failings) isn't W4-clean.
|
|
|
|
#if MSC_VERSION
|
|
|
|
#pragma warning(push, 3)
|
2004-07-08 17:22:09 +02:00
|
|
|
#endif
|
|
|
|
|
2004-06-03 15:00:19 +02:00
|
|
|
#include <xercesc/util/XMLString.hpp>
|
|
|
|
#include <xercesc/util/PlatformUtils.hpp>
|
|
|
|
|
|
|
|
#include <xercesc/sax/InputSource.hpp>
|
|
|
|
#include <xercesc/sax/EntityResolver.hpp>
|
|
|
|
#include <xercesc/util/BinMemInputStream.hpp>
|
|
|
|
|
2004-06-09 14:45:42 +02:00
|
|
|
#include <xercesc/sax/SAXParseException.hpp>
|
|
|
|
#include <xercesc/sax/ErrorHandler.hpp>
|
|
|
|
|
2005-08-09 17:55:44 +02:00
|
|
|
// for Xeromyces.cpp (moved here so we only have to #undef new and
|
|
|
|
// revert to W3 once)
|
|
|
|
// The converter uses SAX2, so it should [theoretically]
|
|
|
|
// be fairly easy to swap Xerces for something else (if desired)
|
|
|
|
#include <xercesc/sax2/XMLReaderFactory.hpp>
|
|
|
|
#include <xercesc/sax2/DefaultHandler.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
#if MSC_VERSION
|
|
|
|
#pragma warning(pop) // back to W4
|
2004-07-08 17:22:09 +02:00
|
|
|
#endif
|
2004-06-09 14:45:42 +02:00
|
|
|
|
2005-08-09 17:55:44 +02:00
|
|
|
#include "mmgr.h" // restore malloc/new macros
|
|
|
|
|
2004-10-06 16:12:10 +02:00
|
|
|
#include "lib/res/handle.h"
|
2004-06-03 15:00:19 +02:00
|
|
|
#include "lib.h"
|
|
|
|
#include "XercesErrorHandler.h"
|
|
|
|
#include "CStr.h"
|
|
|
|
|
|
|
|
XERCES_CPP_NAMESPACE_USE
|
|
|
|
|
|
|
|
CStr XMLTranscode(const XMLCh *);
|
2004-06-09 15:56:29 +02:00
|
|
|
XMLCh *XMLTranscode(const char *);
|
2004-06-03 15:00:19 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
CLASS : CVFSInputSource
|
|
|
|
DESCRIPTION :
|
|
|
|
Use instead of LocalFileInputSource to read XML files from VFS
|
|
|
|
*/
|
|
|
|
class CVFSInputSource: public InputSource
|
|
|
|
{
|
2004-08-24 19:26:35 +02:00
|
|
|
Handle m_hMem; // from vfs_load
|
2004-06-03 15:00:19 +02:00
|
|
|
void *m_pBuffer;
|
|
|
|
size_t m_BufferSize;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CVFSInputSource():
|
2004-08-24 19:26:35 +02:00
|
|
|
m_hMem(0),
|
2004-06-03 15:00:19 +02:00
|
|
|
m_pBuffer(NULL),
|
|
|
|
m_BufferSize(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
~CVFSInputSource();
|
|
|
|
|
|
|
|
// Open a VFS path for XML parsing
|
|
|
|
// returns 0 if successful, -1 on failure
|
|
|
|
int OpenFile(const char *path);
|
|
|
|
|
2004-07-29 18:17:21 +02:00
|
|
|
// Allow the use of externally-loaded files
|
|
|
|
void OpenBuffer(const char* path, const void* buffer, const size_t buffersize);
|
2004-07-08 17:22:09 +02:00
|
|
|
|
2004-06-03 15:00:19 +02:00
|
|
|
virtual BinInputStream *makeStream() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CVFSEntityResolver: public EntityResolver
|
|
|
|
{
|
|
|
|
const char *m_DocName;
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual InputSource *resolveEntity(
|
|
|
|
const XMLCh *const publicId,
|
|
|
|
const XMLCh *const systemId);
|
|
|
|
|
|
|
|
inline CVFSEntityResolver(const char *docName):
|
|
|
|
m_DocName(docName)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _XercesVFS_H
|