textwriter.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. Copyright (c) 2010, Florian Reuter
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7. * Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in
  11. the documentation and/or other materials provided with the
  12. distribution.
  13. * Neither the name of Florian Reuter nor the names of its contributors
  14. may be used to endorse or promote products derived from this
  15. software without specific prior written permission.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  17. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  18. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  19. FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  20. COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  22. BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  25. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  27. OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. /** @file mce/textwriter.h
  30. */
  31. #include <mce/config.h>
  32. #include <libxml/xmlwriter.h>
  33. #include <mce/helper.h>
  34. #ifndef MCE_TEXTWRITER_H
  35. #define MCE_TEXTWRITER_H
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. /**
  40. Default flags for an MCE namespace declaration.
  41. */
  42. #define MCE_DEFAULT 0x0
  43. /**
  44. Flags MCE namespace declaration "ignorable".
  45. */
  46. #define MCE_IGNORABLE 0x1
  47. /**
  48. Flags MCE namespace declaration "must understand".
  49. */
  50. #define MCE_MUSTUNDERSTAND 0x2
  51. /**
  52. The MCE text writer context.
  53. */
  54. typedef struct MCE_TEXTWRITER_STRUCT mceTextWriter;
  55. /**
  56. Create a new MCE text writer.
  57. \see http://xmlsoft.org/html/libxml-xmlIO.html#xmlOutputBufferCreateIO
  58. \see http://xmlsoft.org/html/libxml-xmlwriter.html#xmlNewTextWriter
  59. */
  60. mceTextWriter *mceTextWriterCreateIO(xmlOutputWriteCallback iowrite, xmlOutputCloseCallback ioclose, void *ioctx, xmlCharEncodingHandlerPtr encoder);
  61. /**
  62. Helper which create a new MCE text writer for a FILE handle.
  63. */
  64. mceTextWriter *mceNewTextWriterFile(FILE *file);
  65. /**
  66. Free all resources for \w.
  67. */
  68. int mceTextWriterFree(mceTextWriter *w);
  69. /**
  70. \see http://xmlsoft.org/html/libxml-xmlwriter.html#xmlTextWriterStartDocument
  71. */
  72. int mceTextWriterStartDocument(mceTextWriter *w);
  73. /**
  74. \see http://xmlsoft.org/html/libxml-xmlwriter.html#xmlTextWriterEndDocument
  75. */
  76. int mceTextWriterEndDocument(mceTextWriter *w);
  77. /**
  78. Start a new XML element. If ns==NULL then there is no namespace and ""==ns means the default namespace.
  79. \see http://xmlsoft.org/html/libxml-xmlwriter.html#xmlTextWriterStartElement
  80. \see http://xmlsoft.org/html/libxml-xmlwriter.html#xmlTextWriterStartElementNS
  81. */
  82. int mceTextWriterStartElement(mceTextWriter *w, const xmlChar *ns, const xmlChar *ln);
  83. /**
  84. \see http://xmlsoft.org/html/libxml-xmlwriter.html#xmlTextWriterEndElement
  85. */
  86. int mceTextWriterEndElement(mceTextWriter *w, const xmlChar *ns, const xmlChar *ln);
  87. /**
  88. \see http://xmlsoft.org/html/libxml-xmlwriter.html#xmlTextWriterWriteString
  89. */
  90. int mceTextWriterWriteString(mceTextWriter *w, const xmlChar *content);
  91. /**
  92. Register a namespace. Must be called before mceTextWriterStartElement.
  93. \see MCE_DEFAULT
  94. \see MCE_IGNORABLE
  95. \see MCE_MUSTUNDERSTAND
  96. */
  97. const xmlChar *mceTextWriterRegisterNamespace(mceTextWriter *w, const xmlChar *ns, const xmlChar *prefix, int flags);
  98. /**
  99. Register qname (ns, ln) as a "process content" element wrt. MCE. Must be called before mceTextWriterStartElement.
  100. */
  101. int mceTextWriterProcessContent(mceTextWriter *w, const xmlChar *ns, const xmlChar *ln);
  102. /**
  103. Writes a formatted attribute.
  104. \see http://xmlsoft.org/html/libxml-xmlwriter.html#xmlTextWriterWriteFormatAttribute
  105. */
  106. int mceTextWriterAttributeF(mceTextWriter *w, const xmlChar *ns, const xmlChar *ln, const char *value, ...);
  107. /**
  108. Starts an MCE alternate content section.
  109. */
  110. int mceTextWriterStartAlternateContent(mceTextWriter *w);
  111. /**
  112. Ends an MCE alternate content section.
  113. */
  114. int mceTextWriterEndAlternateContent(mceTextWriter *w);
  115. /**
  116. Start an MCE choice.
  117. */
  118. int mceTextWriterStartChoice(mceTextWriter *w, const xmlChar *ns);
  119. /**
  120. Ends an MCE choice.
  121. */
  122. int mceTextWriterEndChoice(mceTextWriter *w);
  123. /**
  124. Start an MCE fallback.
  125. */
  126. int mceTextWriterStartFallback(mceTextWriter *w);
  127. /**
  128. Ends an MCE fallback.
  129. */
  130. int mceTextWriterEndFallback(mceTextWriter *w);
  131. /**
  132. Returns the underlying xmlTextWriter.
  133. */
  134. xmlTextWriterPtr mceTextWriterIntern(mceTextWriter *w);
  135. /**
  136. Helper which create a new xmlTextWriterPtr for a FILE handle.
  137. */
  138. xmlTextWriterPtr xmlNewTextWriterFile(FILE *file);
  139. #ifdef __cplusplus
  140. } /* extern "C" */
  141. #endif
  142. #endif /* MCE_TEXTWRITER_H */