File: libxml2.c

package info (click to toggle)
gxml 0.20.4%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,364 kB
  • sloc: xml: 131,277; ansic: 786; javascript: 328; python: 88; makefile: 35; sh: 11
file content (28 lines) | stat: -rw-r--r-- 743 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <libxml/tree.h>
#include <stdio.h>
#include <string.h>

int main (void) {
  char *str = "<Bookshelf><Book>Text</Book></Bookshelf>";
  xmlDoc *doc = xmlReadMemory (str, strlen (str), NULL, NULL, 0);

  // to string
  xmlChar *mem;
  int size;
  xmlDocDumpFormatMemoryEnc (doc, &mem, &size, NULL, 0);
  printf ("[%s]\n", (char*)mem);
  xmlFree (mem);

  // set attribute
  xmlNode *root = xmlDocGetRootElement (doc);
  xmlAttr *attr = xmlSetProp (root, "name", "Alice");
  
  xmlFreeDoc (doc);

  /* In C, you'd call this when you were done with the library;
     TODO: do we want to expose this in Vala?  We can't automatically run
     it when we're done using the library from Vala, sadly. */
  //xmlCleanupParser ();

  return 0;
}