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  /// Parse XML in the given file.
51  /// Return true on a successful parse. Return false otherwise.
52  bool parseFile(const char *filename, bool handle_missing_file);
53 
54  /// Return the error message for the last parsing run.
55  /// If no error was thrown in the last parse, then return an empty string.
56  const char *getError() const;
57 
58 protected:
59  /// Parse XML using the current context.
60  /// Return true on a successful parse. Return false otherwise.
61  bool parseContext();
62 
63  /// Helper method for parseContext().
64  /// This must be overridden by the subclass.
65  virtual bool parseContextSubclass() = 0;
66 
67  /// Return the current parsing context.
68  xmlParserCtxtPtr getContext() const;
69 
70  /// Sets the error message for the current parsing run.
71  void setError(const char *error);
72 
73 private:
74 
75  /// Initialize the parsing context.
76  /// Called immediately before a parse takes place.
77  void initializeContext();
78 
79  /// Clean up the parsing context.
80  /// Called immediately after a parse takes place.
81  void cleanupContext();
82 
83  /// The parsing context.
84  xmlParserCtxtPtr myContext;
85 
86  /// Whether the parser should substitute entities.
87  bool mySubstituteEntities;
88 
89  /// Store the error encountered in the last parse run.
90  /// If there was no error in the last parse run,
91  /// then this string is empty.
92  UT_String myError;
93 };
94 
95 #endif
96 
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.
Error getError()
Definition: oidn.hpp:823
GLsizeiptr size
Definition: glcorearb.h:664