xmlschema.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*====================================================================*
  2. *
  3. * void xmlschema ();
  4. *
  5. * node.h
  6. *
  7. * print an XML schema on stdout that is compatible with function
  8. * xmledit; the schema should be used to validate files before any
  9. * attempt is make to parse them;
  10. *
  11. * Motley Tools by Charles Maier;
  12. * Copyright (c) 2001-2006 by Charles Maier Associates;
  13. * Licensed under the Internet Software Consortium License;
  14. *
  15. *--------------------------------------------------------------------*/
  16. #ifndef XMLSCHEMA_SOURCE
  17. #define XMLSCHEMA_SOURCE
  18. #include "../nodes/node.h"
  19. #include "../tools/format.h"
  20. void xmlschema ()
  21. {
  22. unsigned margin = 0;
  23. output (margin, "<?xml version='%s' encoding='%s'?>", XML_VERSION, XML_CHARSET);
  24. output (margin++, "<xs:schema xmlns:xs='%s' elementFormDefault='%s'>", XML_SCHEMA, "qualified");
  25. output (margin++, "<xs:element name='%s'>", DATA_OBJECT);
  26. output (margin++, "<xs:complexType>");
  27. #if 0
  28. output (margin, "<xs:attribute name='%s' use='optional' type='xs:NCName'/>", DATA_NAME);
  29. output (margin, "<xs:attribute name='%s' use='optional' type='xs:string'/>", DATA_TEXT);
  30. #endif
  31. output (margin++, "<xs:sequence>");
  32. output (margin, "<xs:element maxOccurs='unbounded' ref='%s'/>", DATA_MEMBER);
  33. output (margin--, "</xs:sequence>");
  34. output (margin--, "</xs:complexType>");
  35. output (margin--, "</xs:element>");
  36. output (margin++, "<xs:element name='%s'>", DATA_MEMBER);
  37. output (margin++, "<xs:complexType>");
  38. output (margin, "<xs:attribute name='%s' use='required' type='xs:NCName'/>", DATA_NAME);
  39. #if 0
  40. output (margin, "<xs:attribute name='%s' use='optional' type='xs:string'/>", DATA_TEXT);
  41. #endif
  42. output (margin++, "<xs:sequence>");
  43. output (margin++, "<xs:sequence>");
  44. output (margin, "<xs:element ref='%s'/>", DATA_OFFSET);
  45. output (margin, "<xs:element ref='%s'/>", DATA_LENGTH);
  46. output (margin--, "</xs:sequence>");
  47. output (margin++, "<xs:choice>");
  48. output (margin, "<xs:element ref='%s'/>", DATA_STRUCT);
  49. output (margin, "<xs:element ref='%s'/>", DATA_STRING);
  50. output (margin, "<xs:element ref='%s'/>", DATA_HUGE);
  51. output (margin, "<xs:element ref='%s'/>", DATA_LONG);
  52. output (margin, "<xs:element ref='%s'/>", DATA_WORD);
  53. output (margin, "<xs:element ref='%s'/>", DATA_BYTE);
  54. output (margin--, "</xs:choice>");
  55. output (margin--, "</xs:sequence>");
  56. output (margin--, "</xs:complexType>");
  57. output (margin--, "</xs:element>");
  58. output (margin, "<xs:element name='%s' type='xs:positiveInteger'/>", DATA_LENGTH);
  59. output (margin, "<xs:element name='%s' type='xs:hexBinary'/>", DATA_OFFSET);
  60. output (margin++, "<xs:element name='%s'>", DATA_STRUCT);
  61. output (margin++, "<xs:complexType>");
  62. #if 0
  63. output (margin, "<xs:attribute name='%s' use='optional' type='xs:NCName'/>", DATA_NAME);
  64. output (margin, "<xs:attribute name='%s' use='optional' type='xs:string'/>", DATA_TEXT);
  65. #endif
  66. output (margin++, "<xs:choice maxOccurs='unbounded'>");
  67. output (margin, "<xs:element ref='%s'/>", DATA_BYTE);
  68. output (margin, "<xs:element ref='%s'/>", DATA_MEMORY);
  69. output (margin--, "</xs:choice>");
  70. output (margin--, "</xs:complexType>");
  71. output (margin--, "</xs:element>");
  72. output (margin, "<xs:element name='%s' type='xs:string'/>", DATA_STRING);
  73. output (margin, "<xs:element name='%s' type='xs:hexBinary'/>", DATA_MEMORY);
  74. output (margin, "<xs:element name='%s' type='xs:unsignedLong'/>", DATA_HUGE);
  75. output (margin, "<xs:element name='%s' type='xs:unsignedInt'/>", DATA_LONG);
  76. output (margin, "<xs:element name='%s' type='xs:unsignedShort'/>", DATA_WORD);
  77. output (margin, "<xs:element name='%s' type='xs:unsignedByte'/>", DATA_BYTE);
  78. output (margin--, "</xs:schema>");
  79. return;
  80. }
  81. #endif