Guest User

Untitled

a guest
Jun 22nd, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. Part of an xml document:
  2.  
  3. <iq from='tadzik@chopin.edu.pl/nowyklient' to='tadzik@chopin.edu.pl/nowyklient' id='1' type='result'>
  4. <query xmlns='jabber:iq:roster'>
  5.  
  6. Result of my code:
  7.  
  8. Node: iq; From: tadzik@chopin.edu.pl/nowyklient, to: tadzik@chopin.edu.pl/nowyklient, type: result
  9. Node: query; xmlns: (null)
  10.  
  11. Code:
  12.  
  13. #include <stdio.h>
  14. #include <libxml/parser.h>
  15.  
  16. int
  17. main() {
  18. xmlDocPtr dokument;
  19. xmlNodePtr node;
  20. xmlChar *attr, *from, *to, *type;
  21. dokument = xmlParseFile("roster.xml");
  22. if(dokument == NULL) {
  23. fprintf(stderr, "Parsowanie dokumentu nie powiodło się\n");
  24. return 1;
  25. }
  26. node = xmlDocGetRootElement(dokument);
  27. from = xmlGetProp(node, (const xmlChar *)"from");
  28. to = xmlGetProp(node, (const xmlChar *)"to");
  29. type = xmlGetProp(node, (const xmlChar *)"type");
  30. printf("Node: %s; From: %s, to: %s, type: %s\n", node->name, from, to, type);
  31. node = node->xmlChildrenNode;
  32. while(node != NULL) {
  33. if(!xmlStrcmp(node->name, (const xmlChar *)"query")) {
  34. attr = xmlGetProp(node, (const xmlChar *)"xmlns");
  35. printf("Node: %s; xmlns: %s\n", node->name, attr);
  36. xmlFree(attr);
  37. }
  38. node = node->next;
  39. }
  40.  
  41. xmlFreeDoc(dokument);
  42. xmlFree(from);
  43. xmlFree(to);
  44. xmlFree(type);
  45. return 0;
  46. }
Add Comment
Please, Sign In to add comment