JSBSim Flight Dynamics Model 1.3.0 (09 Apr 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
FGXMLParse.cpp
1/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3 Header: FGXMLParse.cpp
4 Author: Jon Berndt
5 Date started: 08/20/2004
6 Purpose: Config file read-in class and XML parser
7 Called by: Various
8
9 ------------- Copyright (C) 2001 Jon S. Berndt (jon@jsbsim.org) -------------
10
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
13 Software Foundation; either version 2 of the License, or (at your option) any
14 later version.
15
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
19 details.
20
21 You should have received a copy of the GNU Lesser General Public License along
22 with this program; if not, write to the Free Software Foundation, Inc., 59
23 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25 Further information about the GNU Lesser General Public License can also be
26 found on the world wide web at http://www.gnu.org.
27
28%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29INCLUDES
30%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
31
32#include "FGXMLParse.h"
33#include "input_output/string_utilities.h"
34#include "input_output/FGLog.h"
35
36using namespace std;
37
38namespace JSBSim {
39
40/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41CLASS IMPLEMENTATION
42%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
43
44void FGXMLParse::reset(void)
45{
46 current_element = document = nullptr;
47 working_string.erase();
48}
49
50//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51
52void FGXMLParse::dumpDataLines(void)
53{
54 if (!working_string.empty()) {
55 for (auto s: split(working_string, '\n'))
56 current_element->AddData(s);
57 }
58 working_string.erase();
59}
60
61//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62
63void FGXMLParse::startElement (const char * name, const XMLAttributes &atts)
64{
65 if (!document) {
66 document = new Element(name);
67 current_element = document;
68 } else {
69 dumpDataLines();
70
71 Element* temp_element = new Element(name);
72 if (temp_element) {
73 temp_element->SetParent(current_element);
74 current_element->AddChildElement(temp_element);
75 }
76 current_element = temp_element;
77 }
78
79 if (!current_element) {
80 LogException err;
81 err << "In file " << getPath() << ": line " << getLine() << "\n"
82 << "No current element read (running out of memory?)\n";
83 throw err;
84 }
85
86 current_element->SetLineNumber(getLine());
87 current_element->SetFileName(getPath());
88
89 for (int i=0; i<atts.size();i++) {
90 current_element->AddAttribute(atts.getName(i), atts.getValue(i));
91 }
92}
93
94//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95
96void FGXMLParse::endElement (const char * name)
97{
98 dumpDataLines();
99 current_element = current_element->GetParent();
100}
101
102//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103
104void FGXMLParse::data (const char * s, int length)
105{
106 working_string += string(s, length);
107}
108
109//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110
111void FGXMLParse::warning (const char * message, int line, int column)
112{
113 FGLogging log(LogLevel::WARN);
114 log << "Warning: " << message << " line: " << line << " column: " << column
115 << "\n";
116}
117
118} // end namespace JSBSim
void SetFileName(const std::string &name)
Set the name of the file in which the element has been read.
Element * GetParent(void)
Returns a pointer to the parent of an element.
void AddAttribute(const std::string &name, const std::string &value)
Stores an attribute belonging to this element.
void SetLineNumber(int line)
Set the line number at which the element has been read.
void AddChildElement(Element *el)
Adds a child element to the list of children stored for this element.
Main namespace for the JSBSim Flight Dynamics Model.
Definition FGFDMExec.cpp:71