Exemplo n.º 1
0
void printElement(const Element& element, const int indent = 0) {
    const string indentation(indent*2, _T(' '));
    std::wcout << indentation << _T("node: ") << element.Name().str() << std::endl;

    if (element.Text()) {
        std::wcout << indentation << _T("text: ") << element.Text().str() << std::endl;
    }

    auto& attributes = element.Attributes();
    if (!attributes.empty()) {
        std::wcout << indentation << _T("attributes: ") << std::endl;
        for (const auto& attribute: attributes) {
            std::wcout << indentation << _T(" ") << attribute.first.str() << _T(": ") << attribute.second.str() << std::endl;
        }
    }

    auto subitems = element.Elements();
    if (!subitems.empty()) {
        std::wcout << indentation << _T("subitems: ") << std::endl;
        for (const auto& e: subitems) {
            printElement(e, indent + 1);
        }
    }
}