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 
22 struct _xmlTextWriter;
23 typedef struct _xmlTextWriter *xmlTextWriterPtr;
24 struct _xmlBuffer;
25 typedef struct _xmlBuffer *xmlBufferPtr;
26 class UT_String;
27 
28 
29 
31 {
32 public:
33  /// Standard constructor.
34  UT_XMLWriter();
35  ~UT_XMLWriter();
36 
37 
38  /// Initializes the writer to write either to memory or to the file.
39  bool beginWritingToFile( const char * file );
40  bool beginWritingToMemory( UT_String & memory );
41 
42  /// Finishes writing, flushes data, and cleans up after writing.
43  /// If writing to memory, this method copies the XML stuff to the
44  /// UT_String passed in earlier.
45  /// If writing to file, it flushes the document and closes the file.
46  bool endWriting();
47 
48 
49  /// Sets the indentation of the XML document elements.
50  bool setIndentation( int spaces_count );
51 
52  /// Write the whole element, ie: @verbatim
53  /// <tag>string</tag>
54  /// @endverbatim
55  bool writeElement( const char * tag, const char * string );
56 
57 
58  /// Begins an element that will contain some other elements or data.
59  bool startElement( const char * tag );
60 
61  /// Ends an element started earlier.
62  bool endElement();
63 
64 
65  /// Sets an attribute for the current element that was started but not yet
66  /// ended.
67  bool writeAttribute( const char * name, const char * value );
68 
69  /// Writes a text string contents data for the current element that was
70  /// started but not yet ended.
71  bool writeString( const char * string );
72 
73 
74  /// Writes a comment.
75  bool writeComment( const char * string );
76 
77  /// Writes string as raw characters. The characters are written exactly
78  /// as they appear, so be careful to use valid XML format, etc.
79  bool writeRawString( const char * string );
80 
81  /// Writes a CDATA element. If data contains "]]>" (which is the CDATA
82  /// termination sequence, then it is split into a few CDATA elements
83  /// (ending in "]]" and starting with ">" to prevent the occurance of this
84  /// reserved sequence.
85  bool writeCDataElement( const char * data );
86 
87 
88 private:
89  // The writer that does the actual writing:
90  xmlTextWriterPtr myWriter;
91 
92  // If the writer is writing to memory, this is the actual buffer the
93  // xml code is written to.
94  xmlBufferPtr myBuffer;
95 
96  // If the writer is writing to memory, this is the string into which the
97  // buffer needs to be copied once writing is done.
98  UT_String * myMemoryString;
99 };
100 
101 #endif
102 
struct _xmlTextWriter * xmlTextWriterPtr
Definition: UT_XMLWriter.h:23
#define UT_API
Definition: UT_API.h:13
void writeString(std::ostream &os, const Name &name)
Definition: Name.h:58
GLboolean * data
Definition: glcorearb.h:130
GLuint const GLchar * name
Definition: glcorearb.h:785
GLsizei const GLfloat * value
Definition: glcorearb.h:823
struct _xmlBuffer * xmlBufferPtr
Definition: UT_XMLWriter.h:25