00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Rafal Jaroszkiewicz 00008 * Side Effects Software Inc 00009 * 123 Front Street West, Suite 1401 00010 * Toronto, Ontario 00011 * Canada M5J 2M2 00012 * 416-504-9876 00013 * 00014 * NAME: UT_XMLWriter.h (UT Library, C++) 00015 * 00016 * COMMENTS: 00017 * A simple wrapper for the xmlwriter. Implements a few methods 00018 * that facilitate some common operations. 00019 * 00020 * This class uses the libxml2 API documented at: 00021 * http://xmlsoft.org/html/libxml-xmlwriter.html 00022 * http://xmlsoft.org/examples/testWriter.c 00023 */ 00024 00025 #ifndef __UT_XMLWriter__ 00026 #define __UT_XMLWriter__ 00027 00028 #include "UT_API.h" 00029 00030 struct _xmlTextWriter; 00031 typedef struct _xmlTextWriter *xmlTextWriterPtr; 00032 struct _xmlBuffer; 00033 typedef struct _xmlBuffer *xmlBufferPtr; 00034 class UT_String; 00035 00036 00037 00038 class UT_API UT_XMLWriter 00039 { 00040 public: 00041 /// Standard constructor. 00042 UT_XMLWriter(); 00043 ~UT_XMLWriter(); 00044 00045 00046 /// Initializes the writer to write either to memory or to the file. 00047 bool beginWritingToFile( const char * file ); 00048 bool beginWritingToMemory( UT_String & memory ); 00049 00050 /// Finishes writing, flushes data, and cleans up after writing. 00051 /// If writing to memory, this method copies the XML stuff to the 00052 /// UT_String passed in earlier. 00053 /// If writing to file, it flushes the document and closes the file. 00054 bool endWriting(); 00055 00056 00057 /// Sets the indentation of the XML document elements. 00058 bool setIndentation( int spaces_count ); 00059 00060 /// Write the whole element, ie: @verbatim 00061 /// <tag>string</tag> 00062 /// @endverbatim 00063 bool writeElement( const char * tag, const char * string ); 00064 00065 00066 /// Begins an element that will contain some other elements or data. 00067 bool startElement( const char * tag ); 00068 00069 /// Ends an element started earlier. 00070 bool endElement(); 00071 00072 00073 /// Sets an attribute for the current element that was started but not yet 00074 /// ended. 00075 bool writeAttribute( const char * name, const char * value ); 00076 00077 /// Writes a text string contents data for the current element that was 00078 /// started but not yet ended. 00079 bool writeString( const char * string ); 00080 00081 00082 /// Writes a comment. 00083 bool writeComment( const char * string ); 00084 00085 /// Writes string as raw characters. The characters are written exactly 00086 /// as they appear, so be careful to use valid XML format, etc. 00087 bool writeRawString( const char * string ); 00088 00089 /// Writes a CDATA element. If data contains "]]>" (which is the CDATA 00090 /// termination sequence, then it is split into a few CDATA elements 00091 /// (ending in "]]" and starting with ">" to prevent the occurance of this 00092 /// reserved sequence. 00093 bool writeCDataElement( const char * data ); 00094 00095 00096 private: 00097 // The writer that does the actual writing: 00098 xmlTextWriterPtr myWriter; 00099 00100 // If the writer is writing to memory, this is the actual buffer the 00101 // xml code is written to. 00102 xmlBufferPtr myBuffer; 00103 00104 // If the writer is writing to memory, this is the string into which the 00105 // buffer needs to be copied once writing is done. 00106 UT_String * myMemoryString; 00107 }; 00108 00109 #endif 00110
1.5.9