stuff-from-scratch/src/web/xml/xml-elements/XmlElement.h
2022-12-06 18:02:43 +00:00

47 lines
1.2 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;
XmlElement* getFirstChildWithTagName(const std::string& tag);
void setText(const std::string& text);
void setTagName(const std::string& tagName);
virtual std::string toString(unsigned depth = 0, bool keepInline = false) const;
protected:
std::string mTagName;
std::string mText;
std::vector<XmlAttributePtr> mAttributes;
std::vector<std::unique_ptr<XmlElement> > mChildren;
};
using XmlElementPtr = std::unique_ptr<XmlElement>;