Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <libxml/xmlreader.h>
- static int check (int rc)
- {
- if (rc == -1) {
- fprintf (stderr, "Error from libxml2, fix your code!\n");
- exit (1);
- }
- }
- void main ()
- {
- // This works well:
- char *s = "<!DOCTYPE doc [<!ENTITY bar 'bar'>]><doc att='foo&bar;'/>";
- // But for the following xml, att2 does not get printed
- // char *s = "<!DOCTYPE doc [<!ENTITY bar 'bar'>]><doc att1='foo&bar;' att2='foo&bar;'/>";
- xmlTextReaderPtr xml = xmlReaderForMemory (s, strlen(s), NULL, NULL, 0);
- while (check (xmlTextReaderRead (xml))) {
- printf ("%s\n", xmlTextReaderConstName (xml));
- while (check (xmlTextReaderMoveToNextAttribute (xml))) {
- const char *attname = xmlTextReaderConstName (xml);
- while (check (xmlTextReaderReadAttributeValue (xml))) {
- printf (" - child of attribute %s with node type %d, name %s and value %s\n",
- attname,
- xmlTextReaderNodeType (xml),
- xmlTextReaderConstName (xml),
- xmlTextReaderConstValue (xml));
- }
- }
- }
- }
- /* Compile with gcc -o attributevalue3 attributevalue3.c `pkg-config --cflags --libs libxml-2.0` */
Add Comment
Please, Sign In to add comment