2022-03-26 21:32:57 +04:30
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Ali Mohammad Pur <mpfard@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
#include <AK/DeprecatedString.h>
|
2022-09-13 17:42:39 +02:00
|
|
|
#include <AK/HashMap.h>
|
2022-03-26 21:32:57 +04:30
|
|
|
#include <AK/Variant.h>
|
|
|
|
#include <AK/Vector.h>
|
|
|
|
#include <LibXML/FundamentalTypes.h>
|
|
|
|
|
|
|
|
namespace XML {
|
|
|
|
|
|
|
|
struct Attribute {
|
|
|
|
Name name;
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString value;
|
2022-03-26 21:32:57 +04:30
|
|
|
};
|
|
|
|
|
2023-08-14 21:56:20 -04:00
|
|
|
struct Offset {
|
|
|
|
size_t offset { 0 };
|
|
|
|
size_t line { 0 };
|
|
|
|
size_t column { 0 };
|
|
|
|
};
|
|
|
|
|
2022-03-26 21:32:57 +04:30
|
|
|
struct Node {
|
|
|
|
struct Text {
|
|
|
|
StringBuilder builder;
|
|
|
|
};
|
|
|
|
struct Comment {
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString text;
|
2022-03-26 21:32:57 +04:30
|
|
|
};
|
|
|
|
struct Element {
|
|
|
|
Name name;
|
2022-12-04 18:02:33 +00:00
|
|
|
HashMap<Name, DeprecatedString> attributes;
|
2023-03-06 17:16:25 +01:00
|
|
|
Vector<NonnullOwnPtr<Node>> children;
|
2022-03-26 21:32:57 +04:30
|
|
|
};
|
|
|
|
|
|
|
|
bool operator==(Node const&) const;
|
|
|
|
|
2023-08-14 21:56:20 -04:00
|
|
|
Offset offset;
|
2022-03-26 21:32:57 +04:30
|
|
|
Variant<Text, Comment, Element> content;
|
|
|
|
Node* parent { nullptr };
|
2023-08-14 21:01:50 -04:00
|
|
|
|
|
|
|
bool is_text() const { return content.has<Text>(); }
|
|
|
|
Text const& as_text() const { return content.get<Text>(); }
|
|
|
|
|
|
|
|
bool is_comment() const { return content.has<Comment>(); }
|
|
|
|
Comment const& as_comment() const { return content.get<Comment>(); }
|
|
|
|
|
|
|
|
bool is_element() const { return content.has<Element>(); }
|
|
|
|
Element const& as_element() const { return content.get<Element>(); }
|
2022-03-26 21:32:57 +04:30
|
|
|
};
|
|
|
|
}
|