#include <iostream>
#include "tinyxml.h"

int main() {
    TiXmlDocument doc;
    doc.LoadFile("xmlfile.xml");

    if (doc.Error()) {
        std::cerr << "加载 XML 文件失败: " << doc.ErrorDesc() << std::endl;
        return 1;
    }

    TiXmlElement* root = doc.RootElement();
    if (root == nullptr) {
        std::cerr << "XML 文件中没有根元素" << std::endl;
        return 1;
    }

    std::cout << "XML 文件的根元素名称: " << root->Value() << std::endl;

    TiXmlElement* child = root->FirstChildElement();
    while (child != nullptr) {
        std::cout << "子元素名称: " << child->Value() << ", 属性: ";
        TiXmlAttribute* attr = child->FirstAttribute();
        while (attr != nullptr) {
            std::cout << attr->Name() << "=" << attr->Value() << ", ";
            attr = attr->Next();
        }
        std::cout << std::endl;
        child = child->NextSiblingElement();
    }

    return 0;
}
