| 50 | } |
| 51 | |
| 52 | void CcComment::FromXml(const std::string& xml_snippet) { |
| 53 | if (xml_snippet.empty()) { |
| 54 | return; |
| 55 | } |
| 56 | try { |
| 57 | auto xml_file = CreateXmlFile("Expat"); |
| 58 | if (!xml_file) { |
| 59 | throw std::runtime_error("Failed to create EXPAT parser object"); |
| 60 | } |
| 61 | const bool parse = xml_file->ParseString(xml_snippet); |
| 62 | if (!parse) { |
| 63 | throw std::runtime_error("Failed to parse the XML string."); |
| 64 | } |
| 65 | const auto* root_node = xml_file->RootNode(); |
| 66 | if (root_node == nullptr) { |
| 67 | throw std::runtime_error("There is no root node in the XML string"); |
| 68 | } |
| 69 | MdComment::FromXml(*root_node); |
| 70 | |
| 71 | IXmlNode::ChildList node_list; |
| 72 | xml_file->GetChildList(node_list); |
| 73 | for (const IXmlNode* node : node_list) { |
| 74 | if (node == nullptr) { |
| 75 | continue; |
| 76 | } |
| 77 | if (node->IsTagName("COMPU-METHOD")) { |
| 78 | method_.FromXml(*node); |
| 79 | } |
| 80 | } |
| 81 | } catch (const std::exception& err) { |
| 82 | MDF_ERROR() << "Failed to parse the CC comment. Error: " << err.what(); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | |
| 87 | } // namespace mdf |
nothing calls this directly
no test coverage detected