#include#include "tinyxml2.h" using namespace tinyxml2; int main() { XMLDocument xmlDoc; XMLElement* root; xmlDoc.LoadFile("example.xml"); root = xmlDoc.FirstChildElement("root"); if (root->HasAttribute("attribute_name")) { std::cout << "Attribute exists"; } else { std::cout << "Attribute does not exist"; } return 0; }
#includeIn this example, we use the `attribute` function of the PugiXML library to check the existence of two attributes, "attribute1" and "attribute2", in the root element of the XML file "example.xml". If both attributes exist, the program outputs "Attributes exist". Otherwise, it outputs "Attributes do not exist". Package library: PugiXML#include "pugixml.hpp" using namespace pugi; int main() { xml_document xmlDoc; xml_parse_result result = xmlDoc.load_file("example.xml"); xml_node root = xmlDoc.child("root"); if (root.attribute("attribute1") && root.attribute("attribute2")) { std::cout << "Attributes exist"; } else { std::cout << "Attributes do not exist"; } return 0; }