36 #include "FGJSBBase.h" 37 #include "FGXMLParse.h" 38 #include "FGXMLElement.h" 39 #include "input_output/string_utilities.h" 45 IDENT(IdSrc,
"$Id: FGXMLParse.cpp,v 1.16 2014/06/09 11:52:06 bcoconni Exp $");
46 IDENT(IdHdr,ID_XMLPARSE);
54 FGXMLParse::FGXMLParse(
void)
56 first_element_read =
false;
57 current_element = document = 0L;
62 void FGXMLParse::startXML(
void)
68 void FGXMLParse::reset(
void)
70 first_element_read =
false;
71 current_element = document = 0L;
76 void FGXMLParse::endXML(
void)
83 void FGXMLParse::startElement (
const char * name,
const XMLAttributes &atts)
86 Element *temp_element;
88 working_string.erase();
90 if (!first_element_read) {
91 document =
new Element(Name);
92 current_element = document;
93 first_element_read =
true;
95 temp_element =
new Element(Name);
96 temp_element->SetParent(current_element);
97 current_element->AddChildElement(temp_element);
98 current_element = temp_element;
101 if (current_element == 0L) {
102 cerr <<
"In file " << getPath() <<
": line " << getLine() << endl
103 <<
"No current element read (running out of memory?)" << endl;
107 current_element->SetLineNumber(getLine());
108 current_element->SetFileName(getPath());
110 for (
int i=0; i<atts.size();i++) {
111 current_element->AddAttribute(atts.getName(i), atts.getValue(i));
117 void FGXMLParse::endElement (
const char * name)
119 if (!working_string.empty()) {
120 vector <string> work_strings = split(working_string,
'\n');
121 for (
unsigned int i=0; i<work_strings.size(); i++) current_element->AddData(work_strings[i]);
124 current_element = current_element->GetParent();
129 void FGXMLParse::data (
const char * s,
int length)
131 working_string += string(s, length);
136 void FGXMLParse::pi (
const char * target,
const char * data)
142 void FGXMLParse::warning (
const char * message,
int line,
int column)
144 cerr <<
"Warning: " << message <<
" line: " << line <<
" column: " << column << endl;