HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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_String.h"
20 
21 struct _xmlParserCtxt;
22 typedef struct _xmlParserCtxt *xmlParserCtxtPtr;
23 
25 {
26 public:
27  /// Standard constructor.
28  UT_XMLParser();
29 
30  /// Standard destructor.
31  virtual ~UT_XMLParser();
32 
33  /// Set whether the parser will automatically substitute entity references
34  /// with the text of the entities' definitions. By default,
35  /// the parser will not substitute entities so that you do not lose
36  /// the entity reference information.
37  void setSubstituteEntities(bool substitute);
38 
39  /// Parse XML contents stored in memory.
40  /// Return true on a successful parse. Return false otherwise.
41  bool parseMemory(const char *contents, int size=-1);
42 
43  /// Parse XML in the given file.
44  /// Return true on a successful parse. Return false otherwise.
45  bool parseFile(const char *filename);
46 
47  /// Return the error message for the last parsing run.
48  /// If no error was thrown in the last parse, then return an empty string.
49  const char *getError() const;
50 
51 protected:
52  /// Parse XML using the current context.
53  /// Return true on a successful parse. Return false otherwise.
54  bool parseContext();
55 
56  /// Helper method for parseContext().
57  /// This must be overridden by the subclass.
58  virtual bool parseContextSubclass() = 0;
59 
60  /// Return the current parsing context.
61  xmlParserCtxtPtr getContext() const;
62 
63  /// Sets the error message for the current parsing run.
64  void setError(const char *error);
65 
66 private:
67 
68  /// Initialize the parsing context.
69  /// Called immediately before a parse takes place.
70  void initializeContext();
71 
72  /// Clean up the parsing context.
73  /// Called immediately after a parse takes place.
74  void cleanupContext();
75 
76  /// The parsing context.
77  xmlParserCtxtPtr myContext;
78 
79  /// Whether the parser should substitute entities.
80  bool mySubstituteEntities;
81 
82  /// Store the error encountered in the last parse run.
83  /// If there was no error in the last parse run,
84  /// then this string is empty.
85  UT_String myError;
86 };
87 
88 #endif
89 
#define UT_API
Definition: UT_API.h:12
GLsizeiptr size
Definition: glcorearb.h:663
struct _xmlParserCtxt * xmlParserCtxtPtr
Definition: UT_XMLParser.h:22