stuff-from-scratch/src/web/xml/XmlElement.cpp
2020-05-02 08:31:03 +01:00

61 lines
1,023 B
C++

#include "XmlElement.h"
XmlElement::XmlElement(const std::string& tagName)
: mTagName(tagName),
mChildren()
{
}
std::shared_ptr<XmlElement> XmlElement::Create(const std::string& tagName)
{
return std::make_shared<XmlElement>(tagName);
}
void XmlElement::AddChild(std::shared_ptr<XmlElement> child)
{
mChildren.push_back(child);
}
std::string XmlElement::GetTagName() const
{
return mTagName;
}
std::string XmlElement::GetText() const
{
return mText;
}
void XmlElement::SetText(const std::string& text)
{
mText = text;
}
void XmlElement::AddAttribute(XmlAttributePtr attribute)
{
mAttributes.push_back(attribute);
}
XmlAttributePtr XmlElement::GetAttribute(const std::string& attributeName) const
{
for(const auto& attribute : mAttributes)
{
if(attribute->GetName() == attributeName)
{
return attribute;
}
}
return nullptr;
}
std::size_t XmlElement::GetNumAttributes() const
{
return mAttributes.size();
}
std::vector<XmlAttributePtr> XmlElement::GetAttributes()
{
return mAttributes;
}