2 // C++ : Ecriture en XML
4 #include "HexXmlWriter.hxx"
8 enum { M_CLOSED, M_OPEN, M_SAUT };
10 // ========================================================= Constructeur
11 XmlWriter::XmlWriter ()
17 // ========================================================= openXml
18 int XmlWriter::openXml (cpchar nomfic)
22 string fname = nomfic;
25 xml_file = fopen (fname.c_str(), "w");
31 ecrire ("<?xml version='1.0'?>");
34 // ========================================================= closeXml
35 void XmlWriter::closeXml ()
37 while (NOT pile_mark.empty())
45 // ========================================================= addMark
46 void XmlWriter::addMark (cpchar balise, bool jump)
53 pile_etat.top () = M_SAUT;
57 pile_etat.top () = M_CLOSED;
60 // ========================================================= endMark
61 void XmlWriter::endMark ()
64 pile_etat.top () = M_SAUT;
66 // ========================================================= openMark
67 void XmlWriter::openMark (cpchar balise)
74 pile_mark.push (balise);
75 pile_etat.push (M_OPEN);
78 // ========================================================= closeMark
79 void XmlWriter::closeMark (bool jump)
81 string balise = pile_mark.top ();
83 int etat = pile_etat.top ();
88 case M_OPEN : ecrire (" />");
90 case M_SAUT : jumpLine ();
100 if (jump) alaLigne (true);
102 // ========================================================= jumpLine
103 void XmlWriter::jumpLine ()
106 putc ('\n', xml_file);
108 xml_pos = xml_level * xml_decal;
109 for (int nc=0 ; nc < xml_pos ; nc++) putc (' ', xml_file);
111 // ========================================================= ecrire
112 void XmlWriter::ecrire (cpchar mot)
114 int lg = strlen (mot);
117 if (xml_pos >= xml_size)
123 fprintf (xml_file, mot);
125 // ========================================================= alaLigne
126 void XmlWriter::alaLigne (bool force)
128 if (xml_pos==0 && NOT force)
131 fprintf (xml_file, "\n");
134 // ========================================================= addAttribute
135 void XmlWriter::addAttribute (cpchar cle, cpchar valeur)