2 // C++ : Ecriture en XML
4 // Copyright (C) 2009-2014 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, or (at your option) any later version.
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 ()
38 // ========================================================= setStream
39 int XmlWriter::setStream ()
47 // ========================================================= setFile
48 int XmlWriter::setFile (pfile afile)
63 // ========================================================= setFileName
64 int XmlWriter::setFileName (cpchar nomfic)
71 int pext = strlen (nomfic) - 4;
74 string sext = &nomfic[pext];
76 suff = sext != ".xml";
79 string fname = nomfic;
83 xml_file = fopen (fname.c_str(), "w");
92 // ========================================================= startXml
93 int XmlWriter::startXml ()
99 ecrire ("<?xml version='1.0'?>");
102 // ========================================================= closeXml
103 void XmlWriter::closeXml ()
105 while (NOT pile_mark.empty())
108 if (xml_mode == InaFile && xml_file!=stdout)
114 // ========================================================= addMark
115 void XmlWriter::addMark (cpchar balise, bool jump)
122 pile_etat.top () = M_SAUT;
126 pile_etat.top () = M_CLOSED;
129 // ========================================================= endMark
130 void XmlWriter::endMark ()
133 pile_etat.top () = M_SAUT;
135 // ========================================================= openMark
136 void XmlWriter::openMark (cpchar balise)
143 pile_mark.push (balise);
144 pile_etat.push (M_OPEN);
147 // ========================================================= closeMark
148 void XmlWriter::closeMark (bool jump)
150 string balise = pile_mark.top ();
152 int etat = pile_etat.top ();
157 case M_OPEN : ecrire (" />");
159 case M_SAUT : jumpLine ();
169 if (jump) alaLigne (true);
171 // ========================================================= jumpLine
172 void XmlWriter::jumpLine ()
177 xml_pos = xml_level * xml_decal;
180 string space (xml_pos, ' ');
181 addMot (space.c_str());
184 // ========================================================= ecrire
185 void XmlWriter::ecrire (cpchar mot)
187 int lg = strlen (mot);
190 if (xml_pos >= xml_size)
198 // ========================================================= alaLigne
199 void XmlWriter::alaLigne (bool force)
201 if (xml_pos==0 && NOT force)
207 // ========================================================= addAttribute
208 void XmlWriter::addAttribute (cpchar cle, cpchar valeur)