tree2.c revision 38ae7e4efe803ea78b6499cd05a394db32623e41
/*
* section: Tree
* synopsis: Creates a tree
* purpose: Shows how to create document, nodes and dump it to stdout or file.
* usage: tree2 <filename> -Default output: stdout
* author: Lucas Brasilino <brasilino@recife.pe.gov.br>
* copy: see Copyright for the status of this software
*/
#include <stdio.h>
#if defined(LIBXML_TREE_ENABLED) && defined(LIBXML_OUTPUT_ENABLED)
/*
*To compile this file using gcc you can type
*gcc `xml2-config --cflags --libs` -o tree2 tree2.c
*/
/* A simple example how to create DOM. Libxml2 automagically
* allocates the necessary amount of memory to it.
*/
int
{
char buff[256];
int i, j;
/*
* Creates a new document, a node and set it as a root node
*/
/*
* Creates a DTD declaration. Isn't mandatory.
*/
/*
* xmlNewChild() creates a new node, which is "attached" as child node
* of root_node node.
*/
BAD_CAST "content of node 1");
/*
* The same as above, but the new child node doesn't have a content
*/
/*
* xmlNewProp() creates attributes, which is "attached" to an node.
* It returns xmlAttrPtr, which isn't used here.
*/
node =
BAD_CAST "this node has attributes");
/*
* Here goes another way to create nodes. xmlNewNode() and xmlNewText
* creates a node and a text node separately. They are "attached"
* by xmlAddChild()
*/
"other way to create content (which is also a node)");
/*
* A simple loop that "automates" nodes creation
*/
for (i = 5; i < 7; i++) {
for (j = 1; j < 4; j++) {
}
}
/*
* Dumping document to stdio or file
*/
/*free the document */
/*
*Free the global variables that may
*have been allocated by the parser.
*/
/*
* this is to debug memory for regression tests
*/
return(0);
}
#else
int main(void) {
exit(1);
}
#endif