i_xml.h
Go to the documentation of this file.00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef NL_I_XML_H
00025 #define NL_I_XML_H
00026
00027
00028 #undef NL_DONT_USE_EXTERNAL_CODE
00029
00030 #ifndef NL_DONT_USE_EXTERNAL_CODE
00031
00032 #include "types_nl.h"
00033 #include "stream.h"
00034
00035
00036 #include <libxml/parser.h>
00037
00038 namespace NLMISC {
00039
00040
00041 struct EXmlParsingError : public EStream
00042 {
00043 EXmlParsingError ( const std::string& str ) : EStream( str ) {}
00044 };
00045
00090 class CIXml : public IStream
00091 {
00092 friend void xmlGenericErrorFuncRead (void *ctx, const char *msg, ...);
00093 public:
00094
00097 CIXml ();
00098
00099
00100
00101 CIXml (bool tryBinaryMode);
00102
00105 virtual ~CIXml ();
00106
00114 bool init (IStream &stream);
00115
00118 void release ();
00119
00122 xmlNodePtr getRootNode () const;
00123
00126 static xmlNodePtr getFirstChildNode (xmlNodePtr parent, const char *childName);
00127
00130 static xmlNodePtr getNextChildNode (xmlNodePtr last, const char *childName);
00131
00134 static xmlNodePtr getFirstChildNode (xmlNodePtr parent, xmlElementType type);
00135
00138 static xmlNodePtr getNextChildNode (xmlNodePtr last, xmlElementType type);
00139
00142 static uint countChildren (xmlNodePtr node, const char *childName);
00143
00146 static uint countChildren (xmlNodePtr node, xmlElementType type);
00147
00153 static bool getPropertyString (std::string &result, xmlNodePtr node, const char *property);
00154
00158 static int getIntProperty(xmlNodePtr node, const char *property, int defaultValue);
00159
00163 static double getFloatProperty(xmlNodePtr node, const char *property, float defaultValue);
00164
00168 static std::string getStringProperty(xmlNodePtr node, const char *property, const std::string& defaultValue);
00169
00175 static bool getContentString (std::string &result, xmlNodePtr node);
00176
00177 private:
00178
00180 virtual void serial(uint8 &b);
00181 virtual void serial(sint8 &b);
00182 virtual void serial(uint16 &b);
00183 virtual void serial(sint16 &b);
00184 virtual void serial(uint32 &b);
00185 virtual void serial(sint32 &b);
00186 virtual void serial(uint64 &b);
00187 virtual void serial(sint64 &b);
00188 virtual void serial(float &b);
00189 virtual void serial(double &b);
00190 virtual void serial(bool &b);
00191 #ifndef NL_OS_CYGWIN
00192 virtual void serial(char &b);
00193 #endif
00194 virtual void serial(std::string &b);
00195 virtual void serial(ucstring &b);
00196 virtual void serialBuffer(uint8 *buf, uint len);
00197 virtual void serialBit(bool &bit);
00198
00199 virtual bool xmlPushBeginInternal (const char *nodeName);
00200 virtual bool xmlPushEndInternal ();
00201 virtual bool xmlPopInternal ();
00202 virtual bool xmlSetAttribInternal (const char *attribName);
00203 virtual bool xmlBreakLineInternal ();
00204 virtual bool xmlCommentInternal (const char *comment);
00205
00206
00207 void serialSeparatedBufferIn ( std::string &value, bool checkSeparator = true );
00208 inline void flushContentString ();
00209
00210
00211 bool _PushBegin;
00212
00213
00214 bool _AttribPresent;
00215
00216
00217 std::string _AttribName;
00218
00219
00220 xmlNodePtr _CurrentNode;
00221
00222
00223 xmlNodePtr _CurrentElement;
00224
00225
00226 xmlParserCtxtPtr _Parser;
00227
00228
00229 std::string _ContentString;
00230
00231
00232 uint _ContentStringIndex;
00233
00234
00235 std::string _ErrorString;
00236
00237
00238 bool _TryBinaryMode;
00239
00240
00241 IStream *_BinaryStream;
00242 };
00243
00244
00245 }
00246
00247 #endif // NL_DONT_USE_EXTERNAL_CODE
00248
00249 #endif // NL_I_XML_H
00250
00251