Source Code File 07-02_newxml2
07-02_newxml2.c
#include <stdio.h>
#include <stdlib.h>
#include <libxml/parser.h>
int main()
{
const xmlChar *r = (const xmlChar *)"root";
xmlDocPtr doc;
xmlNodePtr root;
doc = xmlNewDoc( (const xmlChar *)"1.0");
root = xmlNewDocNode( doc, NULL, r, NULL);
xmlDocSetRootElement( doc, root );
xmlSaveFormatFile( "-", doc, 0 );
xmlFreeDoc(doc);
return(0);
}
Output
<?xml version="1.0"?>
<root/>
Notes
* An empty root tag is shown as empty, which is still valid though questionably useful.
Copyright © 1997-2025 by QPBC.
All rights reserved
