View difference between Paste ID: 3kPZxJp4 and dt3YnAYx
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 = "<!ENTITY bar 'bar'><elem att='foo&bar;'/>";
16+
	// This works well:
17
	char *s = "<!DOCTYPE elem [<!ENTITY bar 'bar'>]><doc att='foo&bar;'/>";
18
	// But for the following xml, att2 does not get printed
19
	// char *s = "<!DOCTYPE elem [<!ENTITY bar 'bar'>]><doc att1='foo&bar;' att2='foo&bar;'/>";
20-
	while (check (xmlTextReaderRead (xml)) {
20+
21
	xmlTextReaderPtr xml = xmlReaderForMemory (s, strlen(s), NULL, NULL, 0);
22-
		while (check (xmlTextReaderMoveToNextAttribute (xml)) {
22+
23-
			while (check (xmlTextReaderReadAttributeValue (xml)) {
23+
	while (check (xmlTextReaderRead (xml))) {
24-
				printf ("child of attribute with node type %d and value %s\n",
24+
25
		while (check (xmlTextReaderMoveToNextAttribute (xml))) {
26
			const char *attname = xmlTextReaderConstName (xml);
27
			while (check (xmlTextReaderReadAttributeValue (xml))) {
28
				printf (" - child of attribute %s with node type %d, name %s and value %s\n",
29
					attname,
30
					xmlTextReaderNodeType (xml),
31
					xmlTextReaderConstName (xml),
32-
/* Compile with gcc -o attributevalue attributevalue.c `pkg-config --cflags --libs libxml-2.0` */
32+
33
			}
34
		}
35
	}
36
}
37
38
/* Compile with gcc -o attributevalue3 attributevalue3.c `pkg-config --cflags --libs libxml-2.0` */