MCPcopy Create free account
hub / github.com/BehaviorTree/Groot / parseXML

Method parseXML

bt_editor/graveyard/model_repository_dialog.cpp:160–202  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

158
159
160bool ModelsRepositoryDialog::parseXML(const QString &filename,
161 ModelsByFile& models_by_file,
162 QString* error_message)
163{
164 TreeNodeModel models;
165 QDomDocument doc;
166 doc.LoadFile( filename.toStdString().c_str() );
167
168 if (doc.Error())
169 {
170 (*error_message) = ("The XML was not correctly loaded");
171 return false;
172 }
173
174 auto strEqual = [](const char* str1, const char* str2) -> bool {
175 return strcmp(str1, str2) == 0;
176 };
177
178 QDomElement* xml_root = doc.documentElement();
179 if (!xml_root || !strEqual(xml_root->Name(), "root"))
180 {
181 (*error_message) = ("The XML must have a root node called <root>");
182 return false;
183 }
184
185 auto meta_root = xml_root.firstChildElement("TreeNodesModel");
186
187 if (!meta_root)
188 {
189 (*error_message) = ("Expecting <TreeNodesModel> under <root>");
190 return false;
191 }
192
193 for( QDomElement node = meta_root.firstChildElement();
194 node != nullptr;
195 node = node.nextSiblingElement() )
196 {
197 models.insert( buildTreeNodeModel(node, true) );
198 }
199 models_by_file.insert( std::make_pair(filename, models) );
200
201 return true;
202}
203
204bool ModelsRepositoryDialog::parseFile(const QString &filename, ModelsByFile &models_by_file)
205{

Callers

nothing calls this directly

Calls 1

NameMethod · 0.80

Tested by

no test coverage detected