MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / FromXml

Method FromXml

lib/mdflib/mdflib/src/hdcomment.cpp:184–232  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

182}
183
184void HdComment::FromXml(const std::string& xml_snippet) {
185 if (xml_snippet.empty()) {
186 return;
187 }
188 try {
189 auto xml_file = CreateXmlFile("Expat");
190 if (!xml_file) {
191 throw std::runtime_error("Failed to create EXPAT parser object");
192 }
193 const bool parse = xml_file->ParseString(xml_snippet);
194 if (!parse) {
195 throw std::runtime_error("Failed to parse the XML string.");
196 }
197 const auto* root_node = xml_file->RootNode();
198 if (root_node == nullptr) {
199 throw std::runtime_error("There is no root node in the XML string");
200 }
201 MdComment::FromXml(*root_node);
202
203 IXmlNode::ChildList node_list;
204 xml_file->GetChildList(node_list);
205 for (const IXmlNode* node : node_list) {
206 if (node == nullptr) {
207 continue;
208 }
209 if (node->IsTagName("time_source") ) {
210 time_source_.FromXml(*node);
211 } else if (node->IsTagName("constants")) {
212 IXmlNode::ChildList const_list;
213 node->GetChildList(const_list);
214 for (const auto* const_node : const_list) {
215 if (const_node == nullptr || !const_node->IsTagName("const")) {
216 continue;
217 }
218 std::string expression = const_node->Value<std::string>();
219 std::string name = const_node->Attribute<std::string>("name", "");
220 MdString temp;
221 temp.FromXml(*const_node);
222 temp.Text(name);
223 AddConstant(temp, expression);
224 }
225 } else if (node->IsTagName("UNIT-SPEC")) {
226 unit_spec_.FromXml(*node);
227 }
228 }
229 } catch (const std::exception& err) {
230 MDF_ERROR() << "Failed to parse the HD comment. Error: " << err.what();
231 }
232}
233
234
235} // namespace mdf

Callers

nothing calls this directly

Calls 7

CreateXmlFileFunction · 0.85
emptyMethod · 0.80
RootNodeMethod · 0.80
IsTagNameMethod · 0.80
ParseStringMethod · 0.45
GetChildListMethod · 0.45
TextMethod · 0.45

Tested by

no test coverage detected