I know how to create a complete dom from an xml file just using XercesDOMParser:
xercesc::XercesDOMParser parser = new xercesc::XercesDOMParser();
parser->parse(path_to_my_file);
parser->getDocument(); // From here on I can access all nodes and do whatever i want
Well, that works... but what if I'd want to parse a string? Something like
std::string myxml = "<root>...</root>";
xercesc::XercesDOMParser parser = new xercesc::XercesDOMParser();
parser->parse(myxml);
parser->getDocument(); // From here on I can access all nodes and do whatever i want
I'm using version 3. Looking inside the AbstractDOMParser
I see that parse method and its overloaded versions, only parse files.
How can I parse from a string?
Use the following overload of XercesDOMParser::parse():
passing it a MemBufInputSource:
Create a
MemBufInputSource
andparse
that:Im doing it another way. If this is incorrect, please tell me why. It seems to work. This is what parse expects:
So you need to put in a DOMLSInput instead of a an InputSource: