#ifndef __XML_H
#define __XML_H

#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/parserInternals.h>

#include "Structures.h"
#include "GraphicalObject.h"
#include "maths_defs.h"

#include <string>
#include <vector>
#include <map>


class Xml 
{
 protected:
  bool        validDocument;
  xmlDocPtr   p_doc;
  xmlNodePtr  p_node;
  std::map<std::string, Noeud*> ids;

 private:
  void tokenize         (const std::string& str,std::vector<std::string>& tokens,const std::string& delimiters);
  
  void getFloatArrayXml (xmlNodePtr node, char* attribname, real x[]);
  void getFloatXml      (xmlNodePtr node, char* attribname,double   &x);
  void getUnsignedXml   (xmlNodePtr node, char* attribname,unsigned &x);

  void makeScene        (Noeud* parent, xmlNodePtr n, std::vector<Noeud *>& obj);
  void addId            (Noeud* node, xmlNodePtr node);
  Noeud* getId          (const std::string&);
  void manageAttach     (Noeud* parent, xmlNodePtr currentNode);

 public:
   Xml(const std::string& filename, bool verbose=false, bool validation=true, bool printInfo=false);
  ~Xml();
  bool documentValid();
  void makeScene(Noeud* parent,std::vector<Noeud *>& obj);
};

#endif
