JSBSim Flight Dynamics Model  1.2.1 (08 Aug 2024)
An Open Source Flight Dynamics and Control Software Library in C++
FGXMLFileRead.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3  Module: FGXMLFileRead.h
4  Author: Jon S. Berndt
5  Date started: 02/04/07
6  Purpose: Shared base class that wraps the XML file reading logic
7 
8  ------------- Copyright (C) 2007 Jon S. Berndt (jon@jsbsim.org) -------------
9 
10  This program is free software; you can redistribute it and/or modify it under
11  the terms of the GNU Lesser General Public License as published by the Free Software
12  Foundation; either version 2 of the License, or (at your option) any later
13  version.
14 
15  This program is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
18  details.
19 
20  You should have received a copy of the GNU Lesser General Public License along with
21  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  Place - Suite 330, Boston, MA 02111-1307, USA.
23 
24  Further information about the GNU Lesser General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26 
27 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28 INCLUDES
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
30 
31 #include "FGXMLFileRead.h"
32 #include "simgear/io/iostreams/sgstream.hxx"
33 
34 namespace JSBSim {
35 
36 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 CLASS IMPLEMENTATION
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39 
40 Element* FGXMLFileRead::LoadXMLDocument(const SGPath& XML_filename,
41  FGXMLParse& fparse, bool verbose)
42 {
43  sg_ifstream infile;
44  SGPath filename(XML_filename);
45  if (!filename.isNull()) {
46  if (filename.extension().empty())
47  filename.concat(".xml");
48  infile.open(filename);
49  if ( !infile.is_open()) {
50  if (verbose) std::cerr << "Could not open file: " << filename << std::endl;
51  return 0L;
52  }
53  } else {
54  std::cerr << "No filename given." << std::endl;
55  return 0L;
56  }
57  readXML(infile, fparse, filename.utf8Str());
58  Element* document = fparse.GetDocument();
59  infile.close();
60  return document;
61 }
62 
63 } // end namespace JSBSim