2 // C++ : Ecriture en XML
4 // Copyright (C) 2009-2012 CEA/DEN, EDF R&D
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HexXmlWriter.hxx"
27 enum { M_CLOSED, M_OPEN, M_SAUT };
29 // ========================================================= Constructeur
30 XmlWriter::XmlWriter ()
37 // ========================================================= openXml
38 int XmlWriter::openXml (cpchar nomfic)
50 int pext = strlen (nomfic) - 4;
53 string sext = &nomfic[pext];
55 suff = sext != ".xml";
57 string fname = nomfic;
60 xml_file = fopen (fname.c_str(), "w");
68 ecrire ("<?xml version='1.0'?>");
71 // ========================================================= closeXml
72 void XmlWriter::closeXml ()
74 while (NOT pile_mark.empty())
82 // ========================================================= addMark
83 void XmlWriter::addMark (cpchar balise, bool jump)
90 pile_etat.top () = M_SAUT;
94 pile_etat.top () = M_CLOSED;
97 // ========================================================= endMark
98 void XmlWriter::endMark ()
101 pile_etat.top () = M_SAUT;
103 // ========================================================= openMark
104 void XmlWriter::openMark (cpchar balise)
111 pile_mark.push (balise);
112 pile_etat.push (M_OPEN);
115 // ========================================================= closeMark
116 void XmlWriter::closeMark (bool jump)
118 string balise = pile_mark.top ();
120 int etat = pile_etat.top ();
125 case M_OPEN : ecrire (" />");
127 case M_SAUT : jumpLine ();
137 if (jump) alaLigne (true);
139 // ========================================================= jumpLine
140 void XmlWriter::jumpLine ()
145 xml_pos = xml_level * xml_decal;
148 string space (xml_pos, ' ');
149 addMot (space.c_str());
152 // ========================================================= ecrire
153 void XmlWriter::ecrire (cpchar mot)
155 int lg = strlen (mot);
158 if (xml_pos >= xml_size)
166 // ========================================================= alaLigne
167 void XmlWriter::alaLigne (bool force)
169 if (xml_pos==0 && NOT force)
175 // ========================================================= addAttribute
176 void XmlWriter::addAttribute (cpchar cle, cpchar valeur)