diff options
author | William Joye <wjoye@cfa.harvard.edu> | 2016-11-17 20:58:44 (GMT) |
---|---|---|
committer | William Joye <wjoye@cfa.harvard.edu> | 2016-11-17 20:58:44 (GMT) |
commit | 4f65b25b474bf534e40c3d3aa47d43e8457fcc9a (patch) | |
tree | 21aab4f800fd8a5046a929b3243edf9d461917d5 /libxml2/doc/examples/io2.c | |
parent | 5720be2a1ff34bf88992db24716f1e489a745e01 (diff) | |
parent | 4464fd97bf7e813b5badf1937e59f6fb5d2be646 (diff) | |
download | blt-4f65b25b474bf534e40c3d3aa47d43e8457fcc9a.zip blt-4f65b25b474bf534e40c3d3aa47d43e8457fcc9a.tar.gz blt-4f65b25b474bf534e40c3d3aa47d43e8457fcc9a.tar.bz2 |
Merge commit '4464fd97bf7e813b5badf1937e59f6fb5d2be646' as 'libxml2'
Diffstat (limited to 'libxml2/doc/examples/io2.c')
-rw-r--r-- | libxml2/doc/examples/io2.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/libxml2/doc/examples/io2.c b/libxml2/doc/examples/io2.c new file mode 100644 index 0000000..4676f4a --- /dev/null +++ b/libxml2/doc/examples/io2.c @@ -0,0 +1,58 @@ +/** + * section: InputOutput + * synopsis: Output to char buffer + * purpose: Demonstrate the use of xmlDocDumpMemory + * to output document to a character buffer + * usage: io2 + * test: io2 > io2.tmp && diff io2.tmp $(srcdir)/io2.res + * author: John Fleck + * copy: see Copyright for the status of this software. + */ + +#include <libxml/parser.h> + +#if defined(LIBXML_TREE_ENABLED) && defined(LIBXML_OUTPUT_ENABLED) +int +main(void) +{ + + xmlNodePtr n; + xmlDocPtr doc; + xmlChar *xmlbuff; + int buffersize; + + /* + * Create the document. + */ + doc = xmlNewDoc(BAD_CAST "1.0"); + n = xmlNewNode(NULL, BAD_CAST "root"); + xmlNodeSetContent(n, BAD_CAST "content"); + xmlDocSetRootElement(doc, n); + + /* + * Dump the document to a buffer and print it + * for demonstration purposes. + */ + xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1); + printf("%s", (char *) xmlbuff); + + /* + * Free associated memory. + */ + xmlFree(xmlbuff); + xmlFreeDoc(doc); + + return (0); + +} +#else +#include <stdio.h> + +int +main(void) +{ + fprintf(stderr, + "library not configured with tree and output support\n"); + return (1); +} +#endif |