#include "XmlWriter.h"

#include "XmlDocument.h"
#include "XmlAttribute.h"

std::string XmlWriter::toString(XmlDocument* document)
{
    std::string content;
    if (auto prolog = document->getProlog())
    {
        content += "<?xml";
        for (const auto& [key, attribute] : prolog->getAttributes())
        {
            content += " " + attribute->getName() + "=\"" + attribute->getValue() + "\"";
        }
        content += "?>\n";
    }

    if (auto root = document->getRoot())
    {
        content += root->toString();
    }
    return content;
}
