I am looking for a tutorial to download an XML file, read it, modify it, and finally save it in C ++. I am using Linux Ubuntu and trying to use Xerces. With Google and many times I could only upload an XML file:
#include <xercesc/parsers/XercesDOMParser.hpp> #include <xercesc/dom/DOM.hpp> #include <xercesc/sax/HandlerBase.hpp> #include <xercesc/util/XMLString.hpp> #include <xercesc/util/PlatformUtils.hpp> #include <iostream> using namespace std; using namespace xercesc; int main (int argc, char* args[]) { try { XMLPlatformUtils::Initialize(); } catch (const XMLException& toCatch) { char* message = XMLString::transcode(toCatch.getMessage()); cout << "Error during initialization! :\n" << message << "\n"; XMLString::release(&message); return 1; } XercesDOMParser* parser = new XercesDOMParser(); parser->setValidationScheme(XercesDOMParser::Val_Always); parser->setDoNamespaces(true); // optional ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase(); parser->setErrorHandler(errHandler); const char* xmlFile = "demo.xml"; try { parser->parse(xmlFile); } catch (const XMLException& toCatch) { char* message = XMLString::transcode(toCatch.getMessage()); cout << "Exception message is: \n" << message << "\n"; XMLString::release(&message); return -1; } catch (const DOMException& toCatch) { char* message = XMLString::transcode(toCatch.msg); cout << "Exception message is: \n" << message << "\n"; XMLString::release(&message); return -1; } catch (...) { cout << "Unexpected Exception \n" ; return -1; } DOMNode* docRootNode; // DOMNode* aNode; DOMDocument* doc; doc = parser->getDocument(); docRootNode = doc->getDocumentElement(); cout << docRootNode->getAttributes() << endl; //returns Hex delete parser; delete errHandler; return 0; }
How can I read the manipulation of an XML file and finally save it? Are there any alternative libraries? (I tried tinyxml, but files return errors when I want to compile them)
c ++ linux xml xerces
user163408
source share