src/tool/xml_document.h

Go to the documentation of this file.
00001 /*
00002  * Exemple d'utilisation de la librairie libxml++ version 1.0.
00003  */
00004 
00005 #ifndef XML_DOCUMENT_H
00006 #define XML_DOCUMENT_H
00007 
00008 #include "../include/base.h"
00009 #include <string>
00010 #include <libxml++/libxml++.h>
00011 
00012 class XmlReader
00013 {
00014 public:
00015   xmlpp::DomParser parser;
00016 
00017 public:
00018   // Load an XML document
00019   bool Load(const std::string &nomfich);
00020 
00021   bool IsOk() const;
00022 
00023   // Get da root man
00024   xmlpp::Element* GetRoot() const;
00025 
00026   // get a attribute marker
00027   static bool ReadString(const xmlpp::Node *father,
00028                          const std::string &name,
00029                          std::string &output);
00030   static bool ReadDouble(const xmlpp::Node *father,
00031                          const std::string &name,
00032                          double &output);
00033   static bool ReadInt(const xmlpp::Node *father,
00034                       const std::string &name,
00035                       int &output);
00036   static bool ReadUint(const xmlpp::Node *father,
00037                        const std::string &name,
00038                        unsigned int &output);
00039   static bool ReadBool(const xmlpp::Node *father,
00040                        const std::string &name,
00041                        bool &output);
00042 
00043   // Get attributes of a marker
00044   static bool ReadStringList(const xmlpp::Node *x, 
00045                              const std::string &name,
00046                              std::list<std::string> &output);
00047 
00048   // Read marker value
00049   static bool ReadMarkerValue(const xmlpp::Node *marker,
00050                                std::string &output);
00051 
00052   // get an XML element
00053   static xmlpp::Element* GetMarker(const xmlpp::Node *x,
00054                                    const std::string &name);
00055 
00056   // Access to the 'anchor' <[name] name="[attr_name]"> : have to be uniq !
00057   static xmlpp::Element* Access(const xmlpp::Node *x,
00058                                 const std::string &name,
00059                                 const std::string &attr_name);
00060 
00061   // Lit un attribut d'un noeud
00062   static bool ReadStringAttr(const xmlpp::Element *x,
00063                              const std::string &name,
00064                              std::string &output);
00065   static bool ReadDoubleAttr(const xmlpp::Element *x,
00066                              const std::string &name,
00067                              double &output);
00068   static bool ReadIntAttr(const xmlpp::Element *x,
00069                           const std::string &name,
00070                           int &output);
00071   static bool ReadUintAttr(const xmlpp::Element *x,
00072                            const std::string &name,
00073                            unsigned int &output);
00074   static bool ReadBoolAttr(const xmlpp::Element *x,
00075                            const std::string &name,
00076                            bool &output);
00077 };
00078 
00079 //-----------------------------------------------------------------------------
00080 
00081 class XmlWriter
00082 {
00083 protected:
00084   xmlpp::Document *m_doc;
00085   xmlpp::Element *m_root;
00086   std::string m_filename;
00087   bool m_save;
00088   std::string m_encoding;
00089 
00090 public:
00091   XmlWriter();
00092   ~XmlWriter();
00093 
00094   bool Create(const std::string &filename, const std::string &root,
00095               const std::string &version, const std::string &encoding);
00096 
00097   bool IsOk() const;
00098 
00099   xmlpp::Element* GetRoot();
00100 
00101   void WriteElement(xmlpp::Element *x,
00102                     const std::string &name,
00103                     const std::string &value);
00104 
00105   bool Save();
00106 };
00107 
00108 #endif /* XML_DOCUMENT_H */

Generated on Mon Jan 1 13:10:59 2007 for Wormux by  doxygen 1.4.7