View difference between Paste ID: jghc1FjZ and kCc1twyB
SHOW: | | - or go back to the newest paste.
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-
	char *s = "<elem att1='foo' att2='bar'/>";
7+
8
	if (rc == -1) {
9
		fprintf (stderr, "Error from libxml2, fix your code!\n");
10
		exit (1);
11-
	while (xmlTextReaderRead (xml) == 1)
11+
	}
12-
		while (xmlTextReaderMoveToNextAttribute (xml) == 1)
12+
13-
			while (xmlTextReaderReadAttributeValue (xml) == 1)
13+
14-
				printf ("%s\n", xmlTextReaderValue (xml));
14+
15
{
16
	char *s = "<elem1 att1='foo1' att2='bar1'/><elem2 att1='foo1' att2='bar2'/>";
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 attributevalue attributevalue.c `pkg-config --cflags --libs libxml-2.0` */