TiXmlDocument doc("example.xml"); doc.LoadFile(); TiXmlElement* root = doc.FirstChildElement("root"); TiXmlAttribute* attr = root->FirstAttribute(); std::string attrName = attr->Name(); // returns attribute name std::string attrValue = attr->Value(); // returns attribute value
TiXmlDocument doc("example.xml"); doc.LoadFile(); TiXmlElement* elem = doc.FirstChildElement("element"); TiXmlAttribute* attr = elem->FindOrCreateAttribute("attrName"); attr->SetValue("attrValue");In this example, we are loading an XML document and retrieving an element by its tag name. We then find an existing attribute or create a new one with the name "attrName" and set its value to "attrValue". Package library: TinyXML.