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
|
|
|
|
|
2023-12-16 17:49:34 +03:30
|
|
|
#include <AK/ByteString.h>
|
2024-02-16 04:55:17 +03:30
|
|
|
#include <AK/GenericLexer.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;
|
2023-12-16 17:49:34 +03:30
|
|
|
ByteString value;
|
2022-03-26 21:32:57 +04:30
|
|
|
};
|
|
|
|
|
|
|
|
struct Node {
|
|
|
|
struct Text {
|
|
|
|
StringBuilder builder;
|
|
|
|
};
|
|
|
|
struct Comment {
|
2023-12-16 17:49:34 +03:30
|
|
|
ByteString text;
|
2022-03-26 21:32:57 +04:30
|
|
|
};
|
|
|
|
struct Element {
|
|
|
|
Name name;
|
2025-08-21 12:11:41 +02:00
|
|
|
OrderedHashMap<Name, ByteString> 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;
|
|
|
|
|
2024-02-16 04:55:17 +03:30
|
|
|
LineTrackingLexer::Position 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
|
|
|
};
|
2025-05-13 07:06:33 -04:00
|
|
|
|
2022-03-26 21:32:57 +04:30
|
|
|
}
|