You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.3 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /******************************************************************
  2. * $Id: ex4.c,v 1.1 2004/06/02 11:20:50 snowdrop Exp $
  3. *
  4. * CSOAP Project: A SOAP client/server library in C
  5. * Copyright (C) 2003 Ferhat Ayaz
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Library General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public
  18. * License along with this library; if not, write to the
  19. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. * Boston, MA 02111-1307, USA.
  21. *
  22. * Email: ayaz@jprogrammet.net
  23. ******************************************************************/
  24. /* This header will be generated by xsd2c */
  25. #include "Person_xsd.h"
  26. /* For stdout writers */
  27. #include "../utils.h"
  28. #include <libxml/parser.h>
  29. struct Person* LoadFromFile(const char* filename)
  30. {
  31. struct Person* person; /* object created by xsd2c */
  32. xmlDocPtr doc;
  33. xmlNodePtr cur;
  34. doc = xmlParseFile(filename);
  35. if (doc == NULL ) {
  36. fprintf(stderr,"Document not parsed successfully. \n");
  37. return NULL;
  38. }
  39. cur = xmlDocGetRootElement(doc);
  40. if (cur == NULL) {
  41. fprintf(stderr,"empty document\n");
  42. xmlFreeDoc(doc);
  43. return NULL;
  44. }
  45. printf("Deserialize ...\n");
  46. person = Person_Deserialize(cur);
  47. printf("Deserialize complete\n");
  48. xmlFreeDoc(doc);
  49. return person;
  50. }
  51. int main(int argc, char *argv[])
  52. {
  53. struct Person* person; /* object created by xsd2c */
  54. if (argc < 2) {
  55. fprintf(stderr, "usage: %s <xml file>\n", argv[0]);
  56. return 1;
  57. }
  58. person = LoadFromFile(argv[1]);
  59. if (person == NULL) {
  60. fprintf(stderr, "Can not deserialize Person\n");
  61. return 1;
  62. }
  63. /* Serialize the Person object. (Just for test)
  64. The 3 sax callback functions
  65. will just print the data to stdout
  66. */
  67. Person_Sax_Serialize(person, "Employee",
  68. Writer_StartElement,
  69. Writer_Characters,
  70. Writer_EndElement, 0);
  71. /* Free the Person */
  72. Person_Free(person);
  73. return 0;
  74. }