func:添加key字段重复检测。
This commit is contained in:
@@ -21,6 +21,14 @@ bool CXmlOpr::parse_xml(std::vector<tinyxml2::XMLElement*>& vec)
|
||||
{
|
||||
std::string next_node{};
|
||||
std::string node_path = opr_base_.node_path;
|
||||
keys_.clear();
|
||||
auto keys = splitString(opr_base_.purpose, ",");
|
||||
for (const auto& item : keys) {
|
||||
if (item.empty()) {
|
||||
continue;
|
||||
}
|
||||
keys_.push_back(item);
|
||||
}
|
||||
|
||||
auto nodes = splitString(opr_base_.node_path, "/");
|
||||
for (const auto& item : nodes) {
|
||||
@@ -71,6 +79,22 @@ void CXmlOpr::del_element(Element_t* ele)
|
||||
parent_node_->DeleteChild(ele);
|
||||
}
|
||||
|
||||
bool CXmlOpr::check_key_exists(const Property_t& property)
|
||||
{
|
||||
if (keys_.size() < 1 || property.size() < 1) {
|
||||
return false;
|
||||
}
|
||||
Element_t* purpose_node = parent_node_->FirstChildElement(opr_base_.the_node.c_str());
|
||||
while (purpose_node) {
|
||||
const char* value = purpose_node->Attribute(keys_[0].c_str());
|
||||
if (property[0].value == std::string(value)) {
|
||||
return true;
|
||||
}
|
||||
purpose_node = purpose_node->NextSiblingElement();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CXmlOpr::save()
|
||||
{
|
||||
auto ret = doc_.SaveFile(xml_path_.c_str());
|
||||
|
||||
Reference in New Issue
Block a user