HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_XMLSaxParser.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_XMLSaxParser.h ( Library, C++)
7  *
8  * COMMENTS:
9  * The SAX 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_XMLSaxParser__
16 #define __UT_XMLSaxParser__
17 
18 #include "UT_API.h"
19 #include "UT_Array.h"
20 #include "UT_String.h"
21 #include "UT_UniquePtr.h"
22 #include "UT_XMLParser.h"
23 
24 #include <utility>
25 
26 struct _xmlSAXHandler;
27 typedef struct _xmlSAXHandler *xmlSAXHandlerPtr;
28 
30 {
31 public:
32  /// Standard constructor.
34 
35  /// Standard destructor.
36  ~UT_XMLSaxParser() override;
37 
38 protected:
39 
40  /// An XML element attribute as defined by a name and a value.
41  typedef std::pair<UT_String, UT_String> UT_XMLAttribute;
42 
43  /// A list of XML element attributes.
45 
46  /// Callback methods that are called at various times
47  /// of the parse.
48  virtual void onStartDocument();
49  virtual void onEndDocument();
50  virtual void onStartElement(const UT_String &name,
51  const UT_XMLAttributeList &attribs);
52  virtual void onEndElement(const UT_String &name);
53  virtual void onCharacters(const UT_String &characters);
54  virtual void onCDATABlock(const UT_String &characters);
55  virtual void onComment(const UT_String &text);
56  virtual void onWarning(const UT_String &text);
57  virtual void onError(const UT_String &text);
58  virtual void onFatalError(const UT_String &text);
59 
60  /// Parse XML using the current context.
61  /// Return true on a successful parse. Return false otherwise.
62  bool parseContextSubclass() override;
63 
64  /// Utility method for getting the value of an attribute.
65  static bool getAttribute(const UT_XMLAttributeList &attribs,
66  const char * name, UT_String & value);
67 private:
68 
69  /// SAX parsing callback handler.
70  UT_UniquePtr<_xmlSAXHandler> myCallbackHandler;
71 
72  /// We need to give the callback helper class
73  /// access to the parser's callback functions (i.e. onStartElement).
74  friend class utSaxParserCallback;
75 };
76 
77 #endif
78 
#define UT_API
Definition: UT_API.h:14
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
UT_Array< UT_XMLAttribute * > UT_XMLAttributeList
A list of XML element attributes.
std::pair< UT_String, UT_String > UT_XMLAttribute
An XML element attribute as defined by a name and a value.
GLuint const GLchar * name
Definition: glcorearb.h:786
Definition: core.h:1131
struct _xmlSAXHandler * xmlSAXHandlerPtr
virtual bool parseContextSubclass()=0