I want to serialize (write) a DOM document out in an XML document. 1.How can i write and to the local file.
crazzycat
Posts
-
About xerces parser. -
Xerces getXML methodint main(int argc, char **argv) { int errorCount = 0; try { XMLPlatformUtils::Initialize(); } catch(const XMLException& toCatch) { cout << "XMLPlatformUtils::Initialize() failed." << endl; XMLPlatformUtils::Terminate(); } std::auto_ptr pXercesDOMParser(new XercesDOMParser()); std::auto_ptr errReporter(new myDOMTreeErrorReporter()); pXercesDOMParser->setErrorHandler(errReporter.get()); XercesDOMParser::ValSchemes valScheme = XercesDOMParser::Val_Auto; pXercesDOMParser->setValidationScheme(valScheme); try { char filename[] = "config/command.xml"; pXercesDOMParser->parse(filename); errorCount = pXercesDOMParser->getErrorCount(); if (errorCount > 0) { cout << "open file failed. 0" << endl; XMLPlatformUtils::Terminate(); //goto Exit; return 0; } } catch (const DOMException& e) { cout << "open file failed. 1" << endl; XMLPlatformUtils::Terminate(); return 0; } catch (const XMLException& e) { cout << "open file failed. 2" << endl; XMLPlatformUtils::Terminate(); return 0; } DOMNode *pDOC = pXercesDOMParser->getDocument(); DOMNode *pNode = pDOC->getFirstChild(); //std::string name(getProp(pNode, "?xml")); for (pNode = getNextElementNode(pNode); pNode != NULL; pNode = getNextElementNode(pNode)) { /*if (!UtilXML::matchNode(pNode, "dictionary"); if (!matchNode(pNode, "dictionary")) { cout << "Bad dictionary format." << endl; break; } std::string proto(getProp(pNode, "protocol")); int currentProtocol = atol(proto.c_str()); #ifdef _DEBUG cout << "protocol = " << currentProtocol << endl; #endif parseDictionary(pNode->getFirstChild(), currentProtocol); */ if(!matchNode(pNode, "command")) { cout << "Bad command format." << endl; break; } parseCommand(pNode, 0); } //Exit: pXercesDOMParser.release(); errReporter.release(); XMLPlatformUtils::Terminate(); return 0; }