XmlDocument.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Co-Author: Claude Sonnet 4.6 (LLM)
  4. * Company: Lynar Studios
  5. * E-Mail: webmaster@lynarstudios.com
  6. * Created: 2020-09-30
  7. * Changed: 2026-06-23
  8. *
  9. * */
  10. #include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
  11. #include <ls-std/io/xml/XmlDocument.hpp>
  12. using ls::standard::core::Class;
  13. using ls::standard::core::NullPointerArgumentEvaluator;
  14. using ls::standard::io::XmlDeclaration;
  15. using ls::standard::io::XmlDocument;
  16. using ls::standard::io::XmlNode;
  17. using std::shared_ptr;
  18. using std::string;
  19. XmlDocument::XmlDocument() : Class("XmlDocument")
  20. {}
  21. XmlDocument::~XmlDocument() noexcept = default;
  22. shared_ptr<XmlDeclaration> XmlDocument::getDeclaration() const
  23. {
  24. return this->declaration;
  25. }
  26. shared_ptr<XmlNode> XmlDocument::getRootElement() const
  27. {
  28. return this->rootElement;
  29. }
  30. void XmlDocument::setDeclaration(const shared_ptr<XmlDeclaration> &_declaration)
  31. {
  32. this->_assignDeclaration(_declaration);
  33. }
  34. void XmlDocument::setRootElement(const shared_ptr<XmlNode> &_rootElement)
  35. {
  36. this->_assignRootElement(_rootElement);
  37. }
  38. string XmlDocument::toXml() const
  39. {
  40. string xmlString{};
  41. if (this->declaration != nullptr)
  42. {
  43. xmlString = this->declaration->toXml();
  44. if (!xmlString.empty())
  45. {
  46. xmlString += "\n";
  47. }
  48. }
  49. return xmlString + this->rootElement->toXml();
  50. }
  51. void XmlDocument::_assignDeclaration(const shared_ptr<XmlDeclaration> &_declaration)
  52. {
  53. NullPointerArgumentEvaluator{_declaration, "xml declaration reference is null!"}.evaluate();
  54. this->declaration = _declaration;
  55. }
  56. void XmlDocument::_assignRootElement(const shared_ptr<XmlNode> &_rootElement)
  57. {
  58. NullPointerArgumentEvaluator{_rootElement, "xml root node reference is null!"}.evaluate();
  59. this->rootElement = _rootElement;
  60. }