Hi ,
I am wokring on migration my project from xerces 1.4 to 3.1 version.
xerces :1.4
You can call the function getElementsByTagName("tagName") on DOM_Element object .
Now with xerces version 3.1 getElementsByTagName requires const XMLCh* as parameter.
So in order to fix this issue simple solution would be as follows:
const XMLCh* tag = xercesc::XMLString::transcode("tagName");
xercesc::DOMNodeList * nodeList = ele->getElementsByTagNames(tag ) ;
My project source code has thousands of lines where we are using the following functions getAttribute setAttribute getElementsByTagName
Currently the parameters passed in this function are ( const char[] ,const char*, std::string )
Inorder to minimise the code changes and writing out transcode function everywhere in the source code I came up with the following header
Snippet showing jsut one function
include <xercesc/dom/DOM.hpp >
include <xercesc/dom/DOMElement.hpp>
include <xercesc/util/XMLString.hpp>
include <string>
class Element : public xercesc::DOMElement
{
public:
inline const XMLCh* getAttribute(std::string &attr)const
{
const XMLCh* att = xercesc::XMLString::transcode( attr.c_str() );
const XMLCh* val = xercesc::DOMElement::getAttribute(att);
return val ;
}
};
So in my source code I simply had to include this header .
Compilation went fine but on linking it gave me the following error
Undefined reference to xercesc::DOMElement( unsigned short const* )
Checking the API I can see the function getAttribute of DOMElement is pure virtual.
virtual const XMLCh * getAttribute (const XMLCh *name) const =0
Retrieves an attribute value by name.
So instead of inheriting from DOMElement I replaced it by DOMElementImpl . It resolved the linking issue but now it core dumps in DOMElementImpl::setAttribute
Program received signal SIGSEGV, Segmentation fault.
0xf7d627c7 in xercesc_3_1::DOMElementImpl::setAttribute () from /vobs/edg/edg_libs/EAS/linux/lib/libxerces-c-3.1.so
Can someone please help me on this issue ?