HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_XMLWriter.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_XMLWriter.h (UT Library, C++)
7  *
8  * COMMENTS:
9  * A simple wrapper for the xmlwriter. Implements a few methods
10  * that facilitate some common operations.
11  *
12  * This class uses the libxml2 API documented at:
13  * http://xmlsoft.org/html/libxml-xmlwriter.html
14  * http://xmlsoft.org/examples/testWriter.c
15  */
16 
17 #ifndef __UT_XMLWriter__
18 #define __UT_XMLWriter__
19 
20 #include "UT_API.h"
21 #include "UT_NonCopyable.h"
22 
23 struct _xmlTextWriter;
24 typedef struct _xmlTextWriter *xmlTextWriterPtr;
25 struct _xmlBuffer;
26 typedef struct _xmlBuffer *xmlBufferPtr;
27 class UT_WorkBuffer;
28 
29 
30 
32 {
33 public:
34  /// Standard constructor.
35  UT_XMLWriter();
36  ~UT_XMLWriter();
37 
39 
40  /// Initializes the writer to write either to memory or to the file.
41  bool beginWritingToFile( const char * file );
42  bool beginWritingToMemory( UT_WorkBuffer & memory );
43 
44  /// Finishes writing, flushes data, and cleans up after writing.
45  /// If writing to memory, this method copies the XML stuff to the
46  /// UT_WorkBuffer passed in earlier.
47  /// If writing to file, it flushes the document and closes the file.
48  bool endWriting();
49 
50 
51  /// Sets the indentation of the XML document elements.
52  bool setIndentation( int spaces_count );
53 
54  /// Write the whole element, ie: @verbatim
55  /// <tag>string</tag>
56  /// @endverbatim
57  bool writeElement( const char * tag, const char * string );
58 
59 
60  /// Begins an element that will contain some other elements or data.
61  bool startElement( const char * tag );
62 
63  /// Ends an element started earlier.
64  bool endElement();
65 
66 
67  /// Sets an attribute for the current element that was started but not yet
68  /// ended.
69  bool writeAttribute( const char * name, const char * value );
70 
71  /// Writes a text string contents data for the current element that was
72  /// started but not yet ended.
73  bool writeString( const char * string );
74 
75 
76  /// Writes a comment.
77  bool writeComment( const char * string );
78 
79  /// Writes string as raw characters. The characters are written exactly
80  /// as they appear, so be careful to use valid XML format, etc.
81  bool writeRawString( const char * string );
82 
83  /// Writes a CDATA element. If data contains "]]>" (which is the CDATA
84  /// termination sequence, then it is split into a few CDATA elements
85  /// (ending in "]]" and starting with ">" to prevent the occurance of this
86  /// reserved sequence.
87  bool writeCDataElement( const char * data );
88 
89 
90 private:
91  // The writer that does the actual writing:
92  xmlTextWriterPtr myWriter;
93 
94  // If the writer is writing to memory, this is the actual buffer the
95  // xml code is written to.
96  xmlBufferPtr myBuffer;
97 
98  // If the writer is writing to memory, this is the buffer into which the
99  // XML document needs to be copied once writing is done.
100  UT_WorkBuffer * myMemoryBuffer;
101 };
102 
103 #endif
104 
GLsizei GLenum GLsizei GLsizei GLuint memory
Definition: RE_OGL.h:202
struct _xmlTextWriter * xmlTextWriterPtr
Definition: UT_XMLWriter.h:24
#define UT_API
Definition: UT_API.h:14
void writeString(std::ostream &os, const Name &name)
Definition: Name.h:33
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
GLuint const GLchar * name
Definition: glcorearb.h:786
Definition: core.h:1131
struct _xmlBuffer * xmlBufferPtr
Definition: UT_XMLWriter.h:26
Definition: format.h:895