42                                 std::filesystem::path& relative_filepath)
 
   44   std::filesystem::path sub_path = path;  
 
   45   if (std::filesystem::is_regular_file(sub_path))
 
   47     relative_filepath = sub_path.filename();  
 
   48     sub_path = sub_path.parent_path();
 
   52     relative_filepath = sub_path;
 
   56   while (!sub_path.empty())
 
   58     if (std::filesystem::is_regular_file(sub_path / 
"package.xml"))
 
   64       tinyxml2::XMLDocument package_xml_file;
 
   65       auto is_open = package_xml_file.LoadFile((sub_path / 
"package.xml").
string().c_str());
 
   66       if (is_open == tinyxml2::XML_SUCCESS)
 
   69             package_xml_file.FirstChildElement(
"package")->FirstChildElement(
"name")->FirstChild()->ToText()->Value();
 
   78     relative_filepath = sub_path.filename() / relative_filepath;
 
   79     sub_path = sub_path.parent_path();
 
   87   for (
const auto& attr : attributes)
 
   91     const char* value = e.Attribute(attr.name);
 
   92     if (value && strcmp(attr.value, value) == 0)
 
  100 tinyxml2::XMLElement* 
uniqueInsert(tinyxml2::XMLDocument& doc, tinyxml2::XMLElement& element, 
const char* tag,
 
  101                                    const std::vector<XMLAttribute>& attributes, 
const char* 
text)
 
  104   tinyxml2::XMLElement* result = element.FirstChildElement(tag);
 
  106     result = result->NextSiblingElement(tag);
 
  110     result = doc.NewElement(tag);
 
  111     element.InsertEndChild(result);
 
  115   for (
const auto& attr : attributes)
 
  117     if (!result->Attribute(attr.name))
 
  118       result->SetAttribute(attr.name, attr.value);
 
  122   if (
text && !result->GetText())
 
  124     tinyxml2::XMLText* text_el = doc.NewText(
text);
 
  125     result->InsertEndChild(text_el);
 
bool hasRequiredAttributes(const tinyxml2::XMLElement &e, const std::vector< XMLAttribute > &attributes)
 
tinyxml2::XMLElement * uniqueInsert(tinyxml2::XMLDocument &doc, tinyxml2::XMLElement &element, const char *tag, const std::vector< XMLAttribute > &attributes={}, const char *text=nullptr)
Insert a new XML element with a given tag, attributes, and text.
 
bool extractPackageNameFromPath(const std::filesystem::path &path, std::string &package_name, std::filesystem::path &relative_filepath)