How to use Xerces to parse XML in a string

752 views Asked by At

I have a C++ project in Visual Studio and I added the Xerces nuget package to it. I am trying to use this library to parse a string of XML that I have retrieved from a SOAP call (SOAP call removed in the simplified example below).

#include <string>
#include <xercesc/parsers/XercesDOMParser.hpp>

using namespace xercesc;

int main() {
    std::string myXMLString = "<a>foo</a>";
    XercesDOMParser* parser = new XercesDOMParser();

    parser->parse(myXMLString);

    //Use the parser object  to interrogate the DOM created from the XML string

    return 0;
}

Obviously this will not work because the parse function does not take a string. Is there another function in the XercesDOMParser class that does? Is there another class I should use?

This question is similar, but in this case, the XML is being loaded from a file: Xerces C++ - Load, read and save, alternatives?

I have tried looking at https://xerces.apache.org for help and some of the pages are useful. For example, in the programming guide, there is clear example code: https://xerces.apache.org/xerces-c/program-3.html. But on the sample page, there is not: https://xerces.apache.org/xerces-c/memparse-3.html. The title of this sample seems to cover what I am trying to do, but it talks about running from the command line; no code.

I am not set on using Xerces, so if you think it is not the best way to accomplish my goals, please say so. I welcome other recommendations.

0

There are 0 answers