Improved compatibility with old libraries (Reported by Kevin Moore)

This commit is contained in:
Zane U. Ji 2014-08-02 13:35:11 +08:00
parent 0cf27535a7
commit 80999d32f9
4 changed files with 133 additions and 7 deletions

View File

@ -184,8 +184,12 @@ const wxMBConv &WrapXerces::getMBConv()
return conv;
}
default:
#ifdef BOOST_STATIC_ASSERT_MSG
BOOST_STATIC_ASSERT_MSG ( sizeof ( XMLCh ) == 2
, "Xerces-C doesn't use UTF-16 strings any more");
#else
BOOST_STATIC_ASSERT ( sizeof ( XMLCh ) == 2 );
#endif
break;
}
return wxConvUTF8;
@ -282,3 +286,115 @@ InputSource *WrapXerces::resolveEntity (
, ( const XMLCh * ) WrapXerces::toString ( publicId ).GetData()
);
}
DOMElement *WrapXerces::getFirstElementChild ( const DOMElement &element )
{
#if _XERCES_VERSION >= 30100
return element.getFirstElementChild();
#else
// Copied from Xerces-C
DOMNode* n = element.getFirstChild();
while ( n )
{
switch ( n->getNodeType() )
{
case DOMNode::ELEMENT_NODE:
return ( DOMElement * ) n;
case DOMNode::ENTITY_REFERENCE_NODE:
{
DOMElement* e = getFirstElementChild ( n );
if ( e )
return e;
break;
}
default:
break;
}
n = n->getNextSibling();
}
return NULL;
#endif
}
DOMElement *WrapXerces::getFirstElementChild ( const DOMNode *n )
{
// Copied from Xerces-C
const DOMNode *top = n;
while ( n )
{
if ( n->getNodeType() == DOMNode::ELEMENT_NODE )
return ( DOMElement * ) n;
DOMNode *next = n->getFirstChild();
while ( !next )
{
if (top == n)
break;
next = n->getNextSibling();
if ( !next )
{
n = n->getParentNode();
if ( top == n || !n )
return NULL;
}
}
n = next;
}
return NULL;
}
DOMElement *WrapXerces::getNextElementSibling (
const DOMElement &element )
{
#if _XERCES_VERSION >= 30100
return element.getNextElementSibling();
#else
// Copied from Xerces-C
DOMNode *n = getNextLogicalSibling ( &element );
while ( n ) {
switch ( n->getNodeType() )
{
case DOMNode::ELEMENT_NODE:
return ( DOMElement * ) n;
case DOMNode::ENTITY_REFERENCE_NODE:
{
DOMElement* e = getFirstElementChild ( n );
if ( e )
return e;
break;
}
default:
break;
}
n = getNextLogicalSibling ( n );
}
return NULL;
#endif
}
DOMNode *WrapXerces::getNextLogicalSibling (
const DOMNode* n )
{
// Copied from Xerces-C
DOMNode* next = n->getNextSibling();
// If "n" has no following sibling and its parent is an entity reference node we
// need to continue the search through the following siblings of the entity
// reference as these are logically siblings of the given node.
if ( !next ) {
DOMNode* parent = n->getParentNode();
while ( parent
&& parent->getNodeType() == DOMNode::ENTITY_REFERENCE_NODE )
{
next = parent->getNextSibling();
if ( next )
break;
parent = parent->getParentNode();
}
}
return next;
}

View File

@ -35,6 +35,7 @@
#include <xercesc/sax2/SAX2XMLReader.hpp>
#include <xercesc/sax2/DefaultHandler.hpp>
#include <xercesc/dom/DOMElement.hpp>
#include "xercescatalogresolver.h"
using namespace xercesc;
@ -129,6 +130,12 @@ class WrapXerces : private boost::noncopyable
const wxString &publicId,
const wxString &systemId,
const wxString &fileName );
static DOMElement *getFirstElementChild ( const DOMElement &element );
static DOMElement *getFirstElementChild ( const DOMNode *n );
static DOMElement *getNextElementSibling ( const DOMElement &element );
static DOMNode *getNextLogicalSibling ( const DOMNode* n );
private:
static const wxMBConv &getMBConv();
static XMLNetAccessor *mOriginalNetAccessor;

View File

@ -878,7 +878,7 @@ MyFrame::MyFrame (
// Initialize Xerces-C++
WrapXerces::Init ( libxmlNetAccess );
#if _XERCES_VERSION >= 30101
#if _XERCES_VERSION >= 30100
if ( XMLPlatformUtils::fgSSE2ok
&& xercescSSE2Warning
&& wxTheApp->argc == 1 )

View File

@ -115,10 +115,11 @@ void XmlSchemaGenerator::findAllElements ( const DOMElement &element,
wxString tagName = WrapXerces::toString ( element.getTagName() );
mElements[tagName].nodes.insert ( &element );
DOMElement *child = element.getFirstElementChild();
for ( ; child != NULL; child = child->getNextElementSibling() )
DOMElement *child = WrapXerces::getFirstElementChild ( element );
while ( child )
{
findAllElements ( *child, nIndent );
child = WrapXerces::getNextElementSibling ( *child );
}
}
@ -131,10 +132,11 @@ void XmlSchemaGenerator::generateData ( const DOMElement &element,
generateData ( name, nIndent );
}
DOMElement *child = element.getFirstElementChild();
for ( ; child != NULL; child = child->getNextElementSibling() )
DOMElement *child = WrapXerces::getFirstElementChild ( element );
while ( child )
{
generateData ( *child, nIndent );
child = WrapXerces::getNextElementSibling ( *child );
}
}
@ -268,10 +270,11 @@ void XmlSchemaGenerator::outputSchema ( const DOMElement &element )
mSchema << data.schema;
}
DOMElement *child = element.getFirstElementChild();
for ( ; child != NULL; child = child->getNextElementSibling() )
DOMElement *child = WrapXerces::getFirstElementChild ( element );
while ( child )
{
outputSchema ( *child );
child = WrapXerces::getNextElementSibling ( *child );
}
}