/* d4.c
*
* Load the XML file specified on the command line and build a DOM tree
* returned as a DOM_Document object. Get the root (yes, that union is a
* little strange -- doesn't happen a lot) and add some new elements using
* a DOM_DocumentFragment object. Then save the result as XML to stdout.
*/
#include <stdlib.h>
#include <stdio.h>
#include "dom.h"
int
main(int argc, char *argv[])
{
DOM_Document *doc;
DOM_DocumentFragment *dfrag;
DOM_Element *root, *e0, *e1;
DOM_Text *t0;
if (argc < 2) {
return EXIT_FAILURE;
}
doc = DOM_Implementation_createDocument(NULL, NULL, NULL);
if (DOM_DocumentLS_load(doc, argv[1]) == 0) {
return EXIT_FAILURE;
}
root = doc->u.Document.documentElement;
dfrag = DOM_Document_createDocumentFragment(doc);
e0 = DOM_Document_createElement(doc, "foo");
e1 = DOM_Document_createElement(doc, "bar");
t0 = DOM_Document_createTextNode(doc, "This tests the DocumentFragment \
operations such as properly moving nodes from the \
DocumentFragment into the children of another.");
DOM_Node_appendChild(dfrag, e0);
DOM_Node_appendChild(dfrag, e1);
DOM_Node_appendChild(dfrag, t0);
if (DOM_Node_appendChild(root->lastChild, dfrag) == NULL) {
return EXIT_FAILURE;
}
if (DOM_DocumentLS_save(doc, "/dev/stdout", NULL) == 0) {
return EXIT_FAILURE;
}
DOM_Document_destroyNode(doc, dfrag);
DOM_Document_destroyNode(doc, doc);
return EXIT_SUCCESS;
}