#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 (std::size_t idx=0; idx< prolog->getNumAttributes(); idx++)
        {
            auto attribute = prolog->getAttribute(idx);
            content += " " + attribute->getName() + "=\"" + attribute->getValue() + "\"";
        }
        content += "?>\n";
    }

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