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

Method FromXml

lib/mdflib/mdflib/src/ccunit.cpp:67–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65}
66
67void CcUnit::FromXml(const std::string& xml_snippet) {
68 if (xml_snippet.empty()) {
69 return;
70 }
71 try {
72 auto xml_file = CreateXmlFile("Expat");
73 if (!xml_file) {
74 throw std::runtime_error("Failed to create EXPAT parser object");
75 }
76 const bool parse = xml_file->ParseString(xml_snippet);
77 if (!parse) {
78 throw std::runtime_error("Failed to parse the XML string.");
79 }
80 const auto* root_node = xml_file->RootNode();
81 if (root_node == nullptr) {
82 throw std::runtime_error("There is no root node in the XML string");
83 }
84 IXmlNode::ChildList node_list;
85 xml_file->GetChildList(node_list);
86 for (const IXmlNode* node : node_list) {
87 if (node == nullptr) {
88 continue;
89 }
90 if (node->IsTagName("ho_unit")) {
91 unit_ref_.MdStandardAttribute::FromXml(*node);
92 if (unit_ref_.Text(node->Attribute<std::string>("unit_ref", ""));
93 unit_ref_.Text().empty() ) {
94 unit_ref_.Text(node->Value<std::string>());
95 }
96 }
97 }
98 MdComment::FromXml(*root_node);
99 } catch (const std::exception& err) {
100 MDF_ERROR() << "Failed to parse the SI comment. Error: " << err.what();
101 }
102}
103
104
105}

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