stuff-from-scratch/src/web/xml/xml-elements/XmlElement.h
2022-12-01 11:49:57 +00:00

43 lines
1.1 KiB
C++

#pragma once
#include <memory>
#include <vector>
#include <string>
class XmlAttribute;
using XmlAttributePtr = std::unique_ptr<XmlAttribute>;
class XmlElement
{
public:
XmlElement(const std::string& tagName);
virtual ~XmlElement();
static std::unique_ptr<XmlElement> Create(const std::string& tagName);
void addAttribute(XmlAttributePtr attribute);
void addChild(std::unique_ptr<XmlElement> child);
const std::string& getTagName() const;
const std::string& getText() const;
XmlAttribute* getAttribute(const std::string& attribute) const;
XmlAttribute* getAttribute(std::size_t index) const;
std::size_t getNumAttributes() const;
std::size_t getNumChildren() const;
XmlElement* getChild(std::size_t index) const;
void setText(const std::string& text);
void setTagName(const std::string& tagName);
protected:
std::string mTagName;
std::string mText;
std::vector<XmlAttributePtr> mAttributes;
std::vector<std::unique_ptr<XmlElement> > mChildren;
};
using XmlElementPtr = std::unique_ptr<XmlElement>;