V-ART
xmlbase.h
Go to the documentation of this file.
1 
5 #ifndef VART_XMLBASE_H
6 #define VART_XMLBASE_H
7 
8 #include <xercesc/parsers/XercesDOMParser.hpp>
9 #include <xercesc/sax/ErrorHandler.hpp>
10 #include <xercesc/dom/DOMDocument.hpp>
11 #include <string>
12 
13 namespace VART {
18  class XmlBase
19  {
20  public:
21  // PUBLIC METHODS
22  protected:
23  // PROTECTED NESTED CLASSES
25  class ErrorHandler : public XERCES_CPP_NAMESPACE::ErrorHandler
26  {
27  friend class XmlScene;
28  public:
29  ErrorHandler();
30  ~ErrorHandler();
31  bool getSawErrors() const;
32  void warning(const XERCES_CPP_NAMESPACE::SAXParseException& e);
33  void error(const XERCES_CPP_NAMESPACE::SAXParseException& e);
34  void fatalError(const XERCES_CPP_NAMESPACE::SAXParseException& e);
35  void resetErrors();
36 
37  private :
38  ErrorHandler(const ErrorHandler&);
39  void operator=(const ErrorHandler&);
40  //This is set if we get any errors, and is queryable via a getter
41  //method. Its used by the main code to suppress output if there are
42  //errors.
43  bool fSawErrors;
44  }; // XmlBase::ErrorHandler
45 
48  {
49  public :
50  TempCString(const XMLCh* const toTranscode)
51  {
52  // Call the private transcoding method
53  cString = XERCES_CPP_NAMESPACE::XMLString::transcode(toTranscode);
54  }
56  {
57  XERCES_CPP_NAMESPACE::XMLString::release(&cString);
58  }
60  bool operator== (const char* other) const;
61 
62  bool GetValue(int* valuePtr) const;
63  bool GetValue(float* valuePtr) const;
64  bool GetValue(bool* valuePtr) const;
65 
67  operator const char* () const
68  {
69  return cString;
70  }
71  private :
72  //This is the local code page form of the string.
73  char* cString;
74  }; // XmlBase::TempCString
75 
78  {
79  public:
80  XercesString(const char* cString)
81  {
82  xString = XERCES_CPP_NAMESPACE::XMLString::transcode(cString);
83  }
85  {
86  XERCES_CPP_NAMESPACE::XMLString::release(&xString);
87  }
89  operator const XMLCh* () const
90  {
91  return xString;
92  }
93  private:
94  XMLCh* xString;
95  }; // XmlBase::XercesString;
96 
97  // PROTECTED STATIC METHODS
103  static bool GetAttributeValue(XERCES_CPP_NAMESPACE::DOMNamedNodeMap* nodePtr,
104  const char itemName[], float* valuePtr);
105 
111  static bool GetAttributeValue(XERCES_CPP_NAMESPACE::DOMNamedNodeMap* nodePtr,
112  const char itemName[], std::string* valuePtr);
113 
119  static bool GetAttributeValue(XERCES_CPP_NAMESPACE::DOMNamedNodeMap* nodePtr,
120  const char itemName[], bool* valuePtr);
121 
122  // PROTECTED METHODS
124  XmlBase();
125 
127  bool ParseFile(const std::string& fileName);
128 
130  void Terminate();
131  // PROTECTED STATIC ATTRIBUTES
132  // PROTECTED ATTRIBUTES
133  XERCES_CPP_NAMESPACE::XercesDOMParser* parserPtr;
134  XERCES_CPP_NAMESPACE::DOMDocument* documentPtr;
135  }; // end class declaration
136 } // end namespace
137 
138 #endif
void warning(const XERCES_CPP_NAMESPACE::SAXParseException &e)
Definition: xmlbase.cpp:227
Basic methods for reading XML files.
Definition: xmlbase.h:18
void fatalError(const XERCES_CPP_NAMESPACE::SAXParseException &e)
Definition: xmlbase.cpp:218
XmlBase()
Creates an unitialized object.
Definition: xmlbase.cpp:24
void error(const XERCES_CPP_NAMESPACE::SAXParseException &e)
Definition: xmlbase.cpp:209
XERCES_CPP_NAMESPACE::XercesDOMParser * parserPtr
Definition: xmlbase.h:133
XERCES_CPP_NAMESPACE::DOMDocument * documentPtr
Definition: xmlbase.h:134
static bool GetAttributeValue(XERCES_CPP_NAMESPACE::DOMNamedNodeMap *nodePtr, const char itemName[], float *valuePtr)
Gets an item value for certain node.
Definition: xmlbase.cpp:136
void Terminate()
Terminates Xerces objects.
Definition: xmlbase.cpp:125
Class for auto conversion from C strings to Xerces strings.
Definition: xmlbase.h:77
bool ParseFile(const std::string &fileName)
Checks if the file comforms to DTD.
Definition: xmlbase.cpp:30
bool getSawErrors() const
Definition: xmlbase.cpp:240
bool operator==(const char *other) const
Check against a C string.
Definition: xmlbase.cpp:160
bool GetValue(int *valuePtr) const
Definition: xmlbase.cpp:165
Class for auto conversion from Xerces strings to C strings.
Definition: xmlbase.h:47
Provides pretty errors messages for Xerces.
Definition: xmlbase.h:25
XercesString(const char *cString)
Definition: xmlbase.h:80
TempCString(const XMLCh *const toTranscode)
Definition: xmlbase.h:50