1

I am not so experienced with c++ and xerces lib, so I want to ask how can I resolve this problem. I installed the xerces lib following the instructions here.

#include <iostream>
#include <string>
#include <sstream>
//Mandatory for using any feature of Xerces.
#include <xercesc/util/PlatformUtils.hpp>
//Use the Document Object Model (DOM) API
#include <xercesc/dom/DOM.hpp>
//Required for outputing a Xerces DOMDocument to a standard output stream (Also see: XMLFormatTarget)
#include <xercesc/framework/StdOutFormatTarget.hpp>
//Required for outputing a Xerces DOMDocument to the file system (Also see: XMLFormatTarget)
#include <xercesc/framework/LocalFileFormatTarget.hpp>

/*
compile with g++ xerces.cc -o xml -lxerces-c
*/

using namespace std;
XERCES_CPP_NAMESPACE_USE

void write_output_to_stream(DOMDocument* measurement_DOM_document);
void write_output_to_file(DOMDocument* measurement_DOM_document, const wchar_t* full_file_path);

int main() {
     XMLPlatformUtils::Initialize();

     /* Pointer to our DOM implementation */
     DOMImplementation* p_dom_implementation = DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("core"));
     /*  */
     DOMDocument* p_dom_document = p_dom_implementation->createDocument(0, L"dummy_measurements", 0);

     DOMElement* p_root_element = p_dom_document->getDocumentElement();

     XMLPlatformUtils::Terminate();
     return 0;
}

This is not the finished code yet, I just tried to compile. Compiler output:

xerces.cc: In function ‘int main()’:
xerces.cc:29:100: error: no matching function for call to ‘xercesc_3_2::DOMImplementation::createDocument(int, const wchar_t [19], int)’
      DOMDocument* p_dom_document = p_dom_implementation->createDocument(0, L"dummy_measurements", 0);
                                                                                                    ^
In file included from /usr/local/include/xercesc/dom/DOM.hpp:41:0,
                 from xerces.cc:7:
/usr/local/include/xercesc/dom/DOMImplementation.hpp:174:26: note: candidate: virtual xercesc_3_2::DOMDocument* xercesc_3_2::DOMImplementation::createDocument(const XMLCh*, const XMLCh*, xercesc_3_2::DOMDocumentType*, xercesc_3_2::MemoryManager*)
     virtual DOMDocument *createDocument(const XMLCh *namespaceURI,
                          ^~~~~~~~~~~~~~
/usr/local/include/xercesc/dom/DOMImplementation.hpp:174:26: note:   no known conversion for argument 2 from ‘const wchar_t [19]’ to ‘const XMLCh* {aka const char16_t*}’
/usr/local/include/xercesc/dom/DOMImplementation.hpp:214:26: note: candidate: virtual xercesc_3_2::DOMDocument* xercesc_3_2::DOMImplementation::createDocument(xercesc_3_2::MemoryManager*)
     virtual DOMDocument *createDocument(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) = 0;
                          ^~~~~~~~~~~~~~
/usr/local/include/xercesc/dom/DOMImplementation.hpp:214:26: note:   candidate expects 1 argument, 3 provided
walnut
  • 21,629
  • 4
  • 23
  • 59
akrilmokus
  • 169
  • 9
  • 1
    You need to convert `const wchar *` to `const XMLCh *`. Maybe https://stackoverflow.com/questions/25839725/xmlch-to-wchar-t-and-vice-versa can help. – vahancho Feb 28 '20 at 14:26
  • 1
    You're battling the difference between wchar_t and char16_t. Use u"..." instead of L"..." to keep the compiler happy about it. https://en.cppreference.com/w/cpp/language/string_literal – Hans Passant Feb 28 '20 at 14:37
  • Thank you Hans Passant, It's worked. – akrilmokus Feb 28 '20 at 14:39
  • I used this, if doesnt fix, XMLString::transcode("") instead L"" – Meric Ozcan Apr 27 '20 at 14:38

0 Answers0