Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Part of an xml document:
- <iq from='tadzik@chopin.edu.pl/nowyklient' to='tadzik@chopin.edu.pl/nowyklient' id='1' type='result'>
- <query xmlns='jabber:iq:roster'>
- Result of my code:
- Node: iq; From: tadzik@chopin.edu.pl/nowyklient, to: tadzik@chopin.edu.pl/nowyklient, type: result
- Node: query; xmlns: (null)
- Code:
- #include <stdio.h>
- #include <libxml/parser.h>
- int
- main() {
- xmlDocPtr dokument;
- xmlNodePtr node;
- xmlChar *attr, *from, *to, *type;
- dokument = xmlParseFile("roster.xml");
- if(dokument == NULL) {
- fprintf(stderr, "Parsowanie dokumentu nie powiodło się\n");
- return 1;
- }
- node = xmlDocGetRootElement(dokument);
- from = xmlGetProp(node, (const xmlChar *)"from");
- to = xmlGetProp(node, (const xmlChar *)"to");
- type = xmlGetProp(node, (const xmlChar *)"type");
- printf("Node: %s; From: %s, to: %s, type: %s\n", node->name, from, to, type);
- node = node->xmlChildrenNode;
- while(node != NULL) {
- if(!xmlStrcmp(node->name, (const xmlChar *)"query")) {
- attr = xmlGetProp(node, (const xmlChar *)"xmlns");
- printf("Node: %s; xmlns: %s\n", node->name, attr);
- xmlFree(attr);
- }
- node = node->next;
- }
- xmlFreeDoc(dokument);
- xmlFree(from);
- xmlFree(to);
- xmlFree(type);
- return 0;
- }
Add Comment
Please, Sign In to add comment