Trying to get entity resolution going in Libxml2

This commit is contained in:
Jez Higgins 2011-12-16 17:40:06 +00:00
parent 3b54b7482a
commit 0316f7ace8
2 changed files with 21 additions and 3 deletions

View file

@ -62,6 +62,8 @@ class libxml2_base
virtual void SAXattributeDecl(const xmlChar *elem, const xmlChar *fullname, int type, int def, const xmlChar *defaultValue, xmlEnumerationPtr tree) = 0;
virtual void SAXentityDecl(const xmlChar *name, int type, const xmlChar *publicId, const xmlChar *systemId, xmlChar *content) = 0;
virtual xmlParserInputPtr SAXresolveEntity(const xmlChar* publicId, const xmlChar* systemId) = 0;
virtual xmlParserCtxtPtr parserContext() = 0;
friend void lwit_startDocument(void* user_data);
friend void lwit_endDocument(void* user_data);
@ -80,6 +82,7 @@ class libxml2_base
friend void lwit_elementDecl(void* user_data, const xmlChar *name, int type, xmlElementContentPtr content);
friend void lwit_attributeDecl(void* user_data, const xmlChar *elem, const xmlChar *fullname, int type, int def, const xmlChar *defaultValue, xmlEnumerationPtr tree);
friend void lwit_entityDecl(void* user_data, const xmlChar *name, int type, const xmlChar *publicId, const xmlChar *systemId, xmlChar *content);
friend xmlEntityPtr lwit_getEntity(void* user_data, const xmlChar* name);
friend xmlParserInputPtr lwit_resolveEntity(void* user_data, const xmlChar* publicId, const xmlChar* systemId);
}; // class libxml2_base
@ -104,6 +107,7 @@ void lwit_attributeDecl(void *user_data, const xmlChar *elem, const xmlChar *ful
void lwit_entityDecl(void* user_data, const xmlChar *name, int type, const xmlChar *publicId, const xmlChar *systemId, xmlChar *content);
void lwit_setFeature(xmlParserCtxtPtr context, const char* name, bool value);
bool lwit_getFeature(xmlParserCtxtPtr context, const char* name);
xmlEntityPtr lwit_getEntity(void* user_data, const xmlChar* name);
xmlParserInputPtr lwit_resolveEntity(void* user_data, const xmlChar* publicId, const xmlChar* systemId);
xmlSAXHandler* lwit_SaxHandler();
} // extern "C"
@ -204,6 +208,8 @@ class libxml2_wrapper :
string_type stringAttrEnum(xmlEnumerationPtr tree, bool leadingSpace) const;
virtual void SAXentityDecl(const xmlChar *name, int type, const xmlChar *publicId, const xmlChar *systemId, xmlChar *content);
virtual xmlParserInputPtr SAXresolveEntity(const xmlChar* publicId, const xmlChar* systemId);
virtual xmlParserCtxtPtr parserContext() { return context_; }
qualifiedNameT processName(const string_type& qName, bool isAttribute);
void reportError(const std::string& message, bool fatal = false);

View file

@ -1,4 +1,4 @@
/*
/*@
* $Id$
*/
@ -27,6 +27,8 @@ std::string formatErrorMsg(const char* fmt, va_list arg)
void lwit_startDocument(void* user_data)
{
libxml2_base* p = reinterpret_cast<libxml2_base*>(user_data);
p->parserContext()->myDoc = xmlNewDoc(p->parserContext()->version);
p->parserContext()->myDoc->intSubset = xmlNewDtd(p->parserContext()->myDoc, BAD_CAST "fake", NULL, NULL);
p->SAXstartDocument();
} // lwit_startDocument
@ -34,6 +36,8 @@ void lwit_endDocument(void* user_data)
{
libxml2_base* p = reinterpret_cast<libxml2_base*>(user_data);
p->SAXendDocument();
xmlFreeDoc(p->parserContext()->myDoc);
p->parserContext()->myDoc = 0;
} // lwit_endDocument
void lwit_startElement(void *user_data, const xmlChar* name, const xmlChar** attrs)
@ -141,6 +145,7 @@ void lwit_entityDecl(void* user_data, const xmlChar *name, int type, const xmlCh
{
libxml2_base* p = reinterpret_cast<libxml2_base*>(user_data);
p->SAXentityDecl(name, type, publicId, systemId, content);
xmlSAX2EntityDecl(p->parserContext(), name, type, publicId, systemId, content);
} // lwit_entityDecl
xmlParserInputPtr lwit_resolveEntity(void* user_data, const xmlChar* publicId, const xmlChar* systemId)
@ -149,6 +154,13 @@ xmlParserInputPtr lwit_resolveEntity(void* user_data, const xmlChar* publicId, c
return p->SAXresolveEntity(publicId, systemId);
} // lwit_resolveEntity
xmlEntityPtr lwit_getEntity(void* user_data, const xmlChar* name)
{
libxml2_base* p = reinterpret_cast<libxml2_base*>(user_data);
xmlEntityPtr ent = xmlSAX2GetEntity(p->parserContext(), name);
return ent;
} // lwit_getEntity
class libxmlInitialiser
{
public:
@ -161,7 +173,7 @@ static xmlSAXHandler saxHandler = {
0, // hasInternalSubsetSAXFunc hasInternalSubset;
0, // hasExternalSubsetSAXFunc hasExternalSubset;
lwit_resolveEntity, // resolveEntitySAXFunc resolveEntity;
0, // getEntitySAXFunc getEntity;
lwit_getEntity, // getEntitySAXFunc getEntity;
lwit_entityDecl, // entityDeclSAXFunc entityDecl;
lwit_notationDecl, // notationDeclSAXFunc notationDecl;
lwit_attributeDecl, // attributeDeclSAXFunc attributeDecl;
@ -188,7 +200,7 @@ static xmlSAXHandler saxHandler = {
0, // _private
0, // startElementNs
0, // endElementNs;
0 // serror;
0 // serror;
};
xmlSAXHandler* lwit_SaxHandler()