View difference between Paste ID: 40CaUPG7 and jghc1FjZ
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
{
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 = "<elem1 att1='foo1' att2='bar1'/><elem2 att1='foo1' att2='bar2'/>";
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)) {
20+
	while (check (xmlTextReaderRead (xml))) {
21
		printf ("%s\n", xmlTextReaderConstName (xml));
22-
		while (check (xmlTextReaderMoveToNextAttribute (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` */
27+
/* Compile with gcc -o attributevalue2 attributevalue2.c `pkg-config --cflags --libs libxml-2.0` */