| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | #include <stdio.h> |
| 12 | #include <libxml/parser.h> |
| 13 | #include <libxml/tree.h> |
| 14 | |
| 15 | #if defined(LIBXML_TREE_ENABLED) && defined(LIBXML_OUTPUT_ENABLED) |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | int |
| 26 | main(int argc, char **argv) |
| 27 | { |
| 28 | xmlDocPtr doc = NULL((void*)0); |
| 29 | xmlNodePtr root_node = NULL((void*)0), node = NULL((void*)0), node1 = NULL((void*)0); |
| 30 | xmlDtdPtr dtd = NULL((void*)0); |
| 31 | char buff[256]; |
| 32 | int i, j; |
| 33 | |
| 34 | LIBXML_TEST_VERSIONxmlCheckVersion(20703);; |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | doc = xmlNewDoc(BAD_CAST(xmlChar *) "1.0"); |
| 40 | root_node = xmlNewNode(NULL((void*)0), BAD_CAST(xmlChar *) "root"); |
| 41 | xmlDocSetRootElement(doc, root_node); |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | dtd = xmlCreateIntSubset(doc, BAD_CAST(xmlChar *) "root", NULL((void*)0), BAD_CAST(xmlChar *) "tree2.dtd"); |
| Value stored to 'dtd' is never read |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | xmlNewChild(root_node, NULL((void*)0), BAD_CAST(xmlChar *) "node1", |
| 53 | BAD_CAST(xmlChar *) "content of node 1"); |
| 54 | |
| 55 | |
| 56 | |
| 57 | xmlNewChild(root_node, NULL((void*)0), BAD_CAST(xmlChar *) "node2", NULL((void*)0)); |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | node = |
| 64 | xmlNewChild(root_node, NULL((void*)0), BAD_CAST(xmlChar *) "node3", |
| 65 | BAD_CAST(xmlChar *) "this node has attributes"); |
| 66 | xmlNewProp(node, BAD_CAST(xmlChar *) "attribute", BAD_CAST(xmlChar *) "yes"); |
| 67 | xmlNewProp(node, BAD_CAST(xmlChar *) "foo", BAD_CAST(xmlChar *) "bar"); |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | node = xmlNewNode(NULL((void*)0), BAD_CAST(xmlChar *) "node4"); |
| 75 | node1 = xmlNewText(BAD_CAST(xmlChar *) |
| 76 | "other way to create content (which is also a node)"); |
| 77 | xmlAddChild(node, node1); |
| 78 | xmlAddChild(root_node, node); |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | for (i = 5; i < 7; i++) { |
| 84 | sprintf(buff, "node%d", i); |
| 85 | node = xmlNewChild(root_node, NULL((void*)0), BAD_CAST(xmlChar *) buff, NULL((void*)0)); |
| 86 | for (j = 1; j < 4; j++) { |
| 87 | sprintf(buff, "node%d%d", i, j); |
| 88 | node1 = xmlNewChild(node, NULL((void*)0), BAD_CAST(xmlChar *) buff, NULL((void*)0)); |
| 89 | xmlNewProp(node1, BAD_CAST(xmlChar *) "odd", BAD_CAST(xmlChar *)((j % 2) ? "no" : "yes")); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | xmlSaveFormatFileEnc(argc > 1 ? argv[1] : "-", doc, "UTF-8", 1); |
| 97 | |
| 98 | |
| 99 | xmlFreeDoc(doc); |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | xmlCleanupParser(); |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | xmlMemoryDump(); |
| 111 | return(0); |
| 112 | } |
| 113 | #else |
| 114 | int main(void) { |
| 115 | fprintf(stderrstderr, "tree support not compiled in\n"); |
| 116 | exit(1); |
| 117 | } |
| 118 | #endif |