Node.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2022, Ali Mohammad Pur <mpfard@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/DeprecatedString.h>
  8. #include <AK/HashMap.h>
  9. #include <AK/Variant.h>
  10. #include <AK/Vector.h>
  11. #include <LibXML/FundamentalTypes.h>
  12. namespace XML {
  13. struct Attribute {
  14. Name name;
  15. DeprecatedString value;
  16. };
  17. struct Node {
  18. struct Text {
  19. StringBuilder builder;
  20. };
  21. struct Comment {
  22. DeprecatedString text;
  23. };
  24. struct Element {
  25. Name name;
  26. HashMap<Name, DeprecatedString> attributes;
  27. Vector<NonnullOwnPtr<Node>> children;
  28. };
  29. bool operator==(Node const&) const;
  30. Variant<Text, Comment, Element> content;
  31. Node* parent { nullptr };
  32. bool is_text() const { return content.has<Text>(); }
  33. Text const& as_text() const { return content.get<Text>(); }
  34. bool is_comment() const { return content.has<Comment>(); }
  35. Comment const& as_comment() const { return content.get<Comment>(); }
  36. bool is_element() const { return content.has<Element>(); }
  37. Element const& as_element() const { return content.get<Element>(); }
  38. };
  39. }