//-- xmlwriter.c --
#include <libxml/xmlversion.h>
#include <libxml/xmlstring.h>
#include <libxml/xmlwriter.h>
int main(void) {
xmlTextWriterPtr writer = xmlNewTextWriterFilename("hello.xml", 0);
if (writer == NULL) {
return EXIT_FAILURE;
}
xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL);
xmlTextWriterWriteComment(writer, BAD_CAST "comment");
xmlTextWriterStartElement(writer, BAD_CAST "root");
xmlTextWriterWriteAttribute(writer, BAD_CAST BAD_CAST "attribute", BAD_CAST "1.0");
xmlTextWriterWriteFormatComment(writer, "format %s", "comment");
xmlTextWriterWriteElement(writer, BAD_CAST "entry", BAD_CAST "Hello World");
xmlTextWriterWriteFormatElement(writer, BAD_CAST "entry", "format %s", BAD_CAST "Hello World");
xmlTextWriterEndElement(writer);
xmlTextWriterEndDocument(writer);
xmlFreeTextWriter(writer);
return EXIT_SUCCESS;
}
/*
$ gcc -I/usr/include/libxml2 -lxml2 xmlwriter.c -oxmlwriter
$ ./xmlwriter
$ cat hello.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--comment--><root attribute="1.0"><!--format comment--><entry>Hello World</entry><entry>format Hello World</entry></root>
*/
2010年1月6日
libxml2 xmlwriter
Libxml2 set of examples
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言