func:可以基本显示目标结果。
This commit is contained in:
47
src/xml_opr.cpp
Normal file
47
src/xml_opr.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "xml_opr.h"
|
||||
|
||||
CXmlOpr::CXmlOpr() = default;
|
||||
CXmlOpr::~CXmlOpr() = default;
|
||||
|
||||
bool CXmlOpr::open(const std::string &xml_path)
|
||||
{
|
||||
if (doc_.LoadFile(xml_path.c_str()) != tinyxml2::XML_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CXmlOpr::set_baseinfo(const OprBase& base)
|
||||
{
|
||||
opr_base_ = base;
|
||||
}
|
||||
|
||||
bool CXmlOpr::parse_xml(std::vector<tinyxml2::XMLElement*>& vec)
|
||||
{
|
||||
std::string next_node{};
|
||||
std::string node_path = opr_base_.node_path;
|
||||
tinyxml2::XMLElement* node = nullptr;
|
||||
|
||||
auto nodes = splitString(opr_base_.node_path, "/");
|
||||
for (const auto& item : nodes) {
|
||||
|
||||
if (item.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (node == nullptr) {
|
||||
node = doc_.FirstChildElement(item.c_str());
|
||||
}
|
||||
else {
|
||||
node = node->FirstChildElement(item.c_str());
|
||||
}
|
||||
}
|
||||
vec.clear();
|
||||
tinyxml2::XMLElement* purpose_node = node->FirstChildElement(opr_base_.the_node.c_str());
|
||||
while (purpose_node)
|
||||
{
|
||||
vec.push_back(purpose_node);
|
||||
purpose_node = purpose_node->NextSiblingElement();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user