level 1
那一开始就是罪
楼主
#include <stdio.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xmlwriter.h>
#define ENCODING ("UTF-8")
//#define ENCODING ("GB2312")
int main(int argc, const char *argv[])
{
xmlDocPtr doc = NULL;
xmlNodePtr root_node = NULL;
xmlTextWriterPtr writer = NULL;
int rc = 0;
doc = xmlNewDoc( BAD_CAST "1.0");
root_node = xmlNewNode( NULL, BAD_CAST "root");
xmlDocSetRootElement( doc, root_node);
writer = xmlNewTextWriterTree(doc, root_node, 0);
rc = xmlTextWriterStartDocument(writer, NULL, ENCODING, "yes");
xmlSaveFormatFileEnc( argc > 1 ? argv[1] : "-", doc, "UTF-8", 1);
xmlSaveFile("xmlcreate.xml",doc);
rc = xmlTextWriterEndDocument(writer);
xmlFreeDoc(doc);
xmlCleanupParser();
xmlMemoryDump();
xmlFreeTextWriter(writer); // the results of xml error 5.
return 0;
}
2013年12月18日 09点12分
1
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xmlwriter.h>
#define ENCODING ("UTF-8")
//#define ENCODING ("GB2312")
int main(int argc, const char *argv[])
{
xmlDocPtr doc = NULL;
xmlNodePtr root_node = NULL;
xmlTextWriterPtr writer = NULL;
int rc = 0;
doc = xmlNewDoc( BAD_CAST "1.0");
root_node = xmlNewNode( NULL, BAD_CAST "root");
xmlDocSetRootElement( doc, root_node);
writer = xmlNewTextWriterTree(doc, root_node, 0);
rc = xmlTextWriterStartDocument(writer, NULL, ENCODING, "yes");
xmlSaveFormatFileEnc( argc > 1 ? argv[1] : "-", doc, "UTF-8", 1);
xmlSaveFile("xmlcreate.xml",doc);
rc = xmlTextWriterEndDocument(writer);
xmlFreeDoc(doc);
xmlCleanupParser();
xmlMemoryDump();
xmlFreeTextWriter(writer); // the results of xml error 5.
return 0;
}