1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 Date started: 08/20/2004
6 Purpose: Config file read-in class and XML parser
9 ------------- Copyright (C) 2001 Jon S. Berndt (jon@jsbsim.org) -------------
11 This program is free software; you can redistribute it and/or modify it under
12 the terms of the GNU Lesser General Public License as published by the Free Software
13 Foundation; either version 2 of the License, or (at your option) any later
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
21 You should have received a copy of the GNU Lesser General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23 Place - Suite 330, Boston, MA 02111-1307, USA.
25 Further information about the GNU Lesser General Public License can also be found on
26 the world wide web at http://www.gnu.org.
28 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
32 #include "FGXMLParse.h"
33 #include "FGXMLElement.h"
37 #include "input_output/string_utilities.h"
43 static const char *IdSrc = "$Id$";
44 static const char *IdHdr = ID_XMLPARSE;
46 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
50 #include "FGXMLParse.h"
54 FGXMLParse::FGXMLParse(void)
56 first_element_read = false;
57 current_element = document = 0L;
60 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 FGXMLParse::~FGXMLParse(void)
67 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 void FGXMLParse::startXML(void)
73 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 void FGXMLParse::reset(void)
78 first_element_read = false;
79 current_element = document = 0L;
82 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84 void FGXMLParse::endXML(void)
86 // At this point, document should equal current_element ?
89 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91 void FGXMLParse::startElement (const char * name, const XMLAttributes &atts)
94 Element *temp_element;
96 working_string.erase();
98 if (!first_element_read) {
99 document = new Element(Name);
100 current_element = document;
101 first_element_read = true;
103 temp_element = new Element(Name);
104 temp_element->SetParent(current_element);
105 current_element->AddChildElement(temp_element);
106 current_element = temp_element;
109 if (current_element == 0L) {
110 cerr << "No current element read (no top-level element in XML file?)" << endl;
114 for (int i=0; i<atts.size();i++) {
115 current_element->AddAttribute(atts.getName(i), atts.getValue(i));
119 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121 void FGXMLParse::endElement (const char * name)
123 if (!working_string.empty()) {
124 vector <string> work_strings = split(working_string, '\n');
125 for (int i=0; i<work_strings.size(); i++) current_element->AddData(work_strings[i]);
128 current_element = current_element->GetParent();
131 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 void FGXMLParse::data (const char * s, int length)
135 working_string += string(s, length);
138 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140 void FGXMLParse::pi (const char * target, const char * data)
144 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146 void FGXMLParse::warning (const char * message, int line, int column)
148 cerr << "Warning: " << message << " line: " << line << " column: " << column << endl;
151 } // end namespace JSBSim