HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_XMLParser.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_XMLParser.h ( Library, C++)
7  *
8  * COMMENTS:
9  * The abstract parser uses the libxml2 API documented at:
10  * http://xmlsoft.org/html/libxml-parser.html
11  * http://xmlsoft.org/html/libxml-tree.html
12  *
13  */
14 
15 #ifndef __UT_XMLParser__
16 #define __UT_XMLParser__
17 
18 #include "UT_API.h"
19 #include "UT_NonCopyable.h"
20 #include "UT_String.h"
21 
22 struct _xmlParserCtxt;
23 typedef struct _xmlParserCtxt *xmlParserCtxtPtr;
24 
26 {
27 public:
28  /// Standard constructor.
29  UT_XMLParser();
30 
31  /// Standard destructor.
32  virtual ~UT_XMLParser();
33 
35 
36  /// Set whether the parser will automatically substitute entity references
37  /// with the text of the entities' definitions. By default,
38  /// the parser will not substitute entities so that you do not lose
39  /// the entity reference information.
40  void setSubstituteEntities(bool substitute);
41 
42  /// Parse XML contents stored in memory.
43  /// Return true on a successful parse. Return false otherwise.
44  bool parseMemory(const char *contents, int size=-1);
45 
46  /// Parse XML in the given file.
47  /// Return true on a successful parse. Return false otherwise.
48  bool parseFile(const char *filename);
49 
50  /// Return the error message for the last parsing run.
51  /// If no error was thrown in the last parse, then return an empty string.
52  const char *getError() const;
53 
54 protected:
55  /// Parse XML using the current context.
56  /// Return true on a successful parse. Return false otherwise.
57  bool parseContext();
58 
59  /// Helper method for parseContext().
60  /// This must be overridden by the subclass.
61  virtual bool parseContextSubclass() = 0;
62 
63  /// Return the current parsing context.
64  xmlParserCtxtPtr getContext() const;
65 
66  /// Sets the error message for the current parsing run.
67  void setError(const char *error);
68 
69 private:
70 
71  /// Initialize the parsing context.
72  /// Called immediately before a parse takes place.
73  void initializeContext();
74 
75  /// Clean up the parsing context.
76  /// Called immediately after a parse takes place.
77  void cleanupContext();
78 
79  /// The parsing context.
80  xmlParserCtxtPtr myContext;
81 
82  /// Whether the parser should substitute entities.
83  bool mySubstituteEntities;
84 
85  /// Store the error encountered in the last parse run.
86  /// If there was no error in the last parse run,
87  /// then this string is empty.
88  UT_String myError;
89 };
90 
91 #endif
92 
GT_API const UT_StringHolder filename
#define UT_API
Definition: UT_API.h:14
< returns > If no error
Definition: snippets.dox:2
struct _xmlParserCtxt * xmlParserCtxtPtr
Definition: UT_XMLParser.h:23
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
GLsizeiptr size
Definition: glcorearb.h:664