Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <libxml/xmlreader.h>
  5.  
  6. static int check (int rc)
  7. {
  8.     if (rc == -1) {
  9.         fprintf (stderr, "Error from libxml2, fix your code!\n");
  10.         exit (1);
  11.     }
  12. }
  13.  
  14. void main ()
  15. {
  16.     char *s = "<doc><elem1 att1='foo1' att2='bar1'/><elem2 att1='foo1' att2='bar2'/></doc>";
  17.    
  18.     xmlTextReaderPtr xml = xmlReaderForMemory (s, strlen(s), NULL, NULL, 0);
  19.    
  20.     while (check (xmlTextReaderRead (xml))) {
  21.         printf ("%s\n", xmlTextReaderConstName (xml));
  22.         while (check (xmlTextReaderMoveToNextAttribute (xml)))
  23.             printf (" - %s: %s\n", xmlTextReaderConstName (xml), xmlTextReaderConstValue (xml));
  24.     }
  25. }
  26.  
  27. /* Compile with gcc -o attributevalue2 attributevalue2.c `pkg-config --cflags --libs libxml-2.0` */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement