1 // Copyright (C) 2009-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // Class : Ecriture d'un fichier XML
22 #ifndef __XML_WRITER_H
23 #define __XML_WRITER_H
25 #include "hexa_base.hxx"
31 class HexaExport XmlWriter
35 ~XmlWriter () { closeXml () ; }
37 int setFileName (cpchar filename); // Un seul xml par fichier
38 int setFile (pfile afile); // Plusieurs xml par fichier
39 int setStream (); // Sauvegarde par flux
42 cpchar getXml () { return xml_buffer.c_str(); }
44 void openMark (cpchar balise); // <Balise ..
45 void addMark (cpchar balise, bool jump=true); // <Balise> + eol
46 void closeMark (bool jump=false); // </Balise> ou />
49 void addAttribute (cpchar attrib, cpchar valeur); // attrib="valeur"
50 void addAttribute (cpchar attrib, int valeur);
51 void addAttribute (cpchar attrib, double valeur);
52 void addAttribute (cpchar attrib, string& valeur);
56 void alaLigne (bool force=false);
57 void ecrire (cpchar mot);
58 void ecrire (string& mot) { ecrire (mot.c_str()) ; }
59 void addMot (cpchar mot);
62 enum {InaFile, InaStudy, InaStream} xml_mode;
63 enum {xml_decal=3, xml_size=80};
69 std::string xml_buffer;
70 std::stack <std::string, std::vector <std::string> > pile_mark;
71 std::stack <int, std::vector <int> > pile_etat;
73 // ====================================================== addAttribute (I)
74 inline void XmlWriter::addAttribute (cpchar attrib, int valeur)
77 sprintf (buffer, "%d", valeur);
78 addAttribute (attrib, buffer);
80 // ====================================================== addAttribute (R)
81 inline void XmlWriter::addAttribute (cpchar attrib, double valeur)
84 sprintf (buffer, "%g", valeur);
85 addAttribute (attrib, buffer);
87 // ====================================================== addAttribute (stl)
88 inline void XmlWriter::addAttribute (cpchar attrib, string& valeur)
90 addAttribute (attrib, valeur.c_str());
92 // ====================================================== addMot
93 inline void XmlWriter::addMot (cpchar mot)
96 fprintf (xml_file, mot);