|
|
Donner 0.8.0-pre
Embeddable browser-grade SVG2 engine
|
Represents an XML document, which holds a collection of XMLNode as the document tree. More...
#include "donner/base/xml/XMLDocument.h"
Public Member Functions | |
| XMLDocument () | |
| Constructor to create an empty XMLDocument. | |
| Registry & | registry () |
| Get the underlying ECS Registry, which holds all data for the document, for advanced use. | |
| std::shared_ptr< Registry > | sharedRegistry () const |
| Gets the registry as a shared pointer, for advanced use. | |
| XMLNode | root () const |
| Get the root XMLNdoe of the document. | |
| EntityHandle | rootEntityHandle () const |
| Get the root ECS Entity of the document, for advanced use. | |
| bool | hasSourceStore () const |
| Return true if this document has an owned source store. | |
| std::string_view | source () const |
| Return the current XML source text. | |
| std::uint64_t | sourceVersion () const |
| Return the source version, or 0 for documents without a source store. | |
| XMLSourceStore * | sourceStore () |
| Get the mutable source store, or nullptr if this document does not own source text. | |
| const XMLSourceStore * | sourceStore () const |
| Get the immutable source store, or nullptr if this document does not own source text. | |
| std::optional< XMLNode > | nodeAtSourceOffset (std::size_t offset) const |
Return the deepest parsed XML node whose current source range contains offset. | |
| std::optional< XMLAttributeAtSourceOffset > | attributeAtSourceOffset (std::size_t offset) const |
Return the attribute whose current source range contains offset, if any. | |
| ApplySourceEditResult | applySourceEdit (const XMLEditIntent &intent) |
| Apply a source edit through this XML document. | |
| ApplySourceEditResult | setAttribute (XMLNode node, const XMLQualifiedNameRef &name, std::string_view value) |
| Set an XML attribute through this document and update owned source text. | |
| ApplySourceEditResult | removeAttribute (XMLNode node, const XMLQualifiedNameRef &name) |
| Remove an XML attribute through this document and update owned source text. | |
| ApplySourceEditResult | insertNode (XMLNode parent, XMLNode node, std::optional< XMLNode > referenceNode=std::nullopt) |
| Insert a source-less XML node under a source-backed parent and update owned source text. | |
| ApplySourceEditResult | removeNode (XMLNode node) |
| Remove a source-backed XML node through this document. | |
| void | setSource (std::string source) |
| Install owned source text for this document. | |
Static Public Member Functions | |
| static XMLDocument | CreateFromRegistry (std::shared_ptr< Registry > registry) |
| Rehydrate an XMLDocument facade from an internal shared registry. | |
Represents an XML document, which holds a collection of XMLNode as the document tree.
Each XMLNode may only belong to a single document, and each document can have only one root. XMLDocument is responsible for managing the lifetime of all elements in the document, by storing a shared pointer to the internal Registry data-store.
Data is stored using the Entity Component System (Entity Component System (ECS)) pattern, which is a data-oriented design optimized for fast data access and cache locality, particularly during rendering.
XMLDocument and XMLNode provide a facade over the ECS, and surface a familiar Document Object Model (DOM) API to traverse and manipulate the document tree, which is internally stored within Components in the ECS. This makes XMLNode a thin wrapper around an Entity, making the object lightweight and usable on the stack.
| donner::xml::XMLDocument::XMLDocument | ( | ) |
Constructor to create an empty XMLDocument.
To load a document from an XML file, use donner::xml::XMLParser.
| ApplySourceEditResult donner::xml::XMLDocument::applySourceEdit | ( | const XMLEditIntent & | intent | ) |
Apply a source edit through this XML document.
This is the incremental editing entry point. It validates the caller's source version, applies the source change through XMLSourceStore, chooses the smallest implemented reparse scope, and emits XML mutations for scopes that can update the live tree.
Implemented local scopes keep source bytes current and either update the live tree or return a scoped diagnostic so callers can preserve the last valid semantic projection while the edited XML is temporarily malformed.
| intent | Source edit request. |
| std::optional< XMLAttributeAtSourceOffset > donner::xml::XMLDocument::attributeAtSourceOffset | ( | std::size_t | offset | ) | const |
Return the attribute whose current source range contains offset, if any.
This currently resolves the containing node, then reparses that node's current opening tag to locate attributes. It is intentionally XML-owned and source-store aware, but does not yet require long-lived per-attribute anchors.
| offset | Byte offset in the current XML source. |
|
static |
Rehydrate an XMLDocument facade from an internal shared registry.
| registry | Shared XML document registry to wrap. |
| ApplySourceEditResult donner::xml::XMLDocument::insertNode | ( | XMLNode | parent, |
| XMLNode | node, | ||
| std::optional< XMLNode > | referenceNode = std::nullopt ) |
Insert a source-less XML node under a source-backed parent and update owned source text.
The first implementation supports inserting an unparented node into an element that has a parsed closing tag. If referenceNode is set, it must be an existing child of parent and the new node is inserted immediately before it; otherwise the new node is appended before parent 's closing tag.
| parent | Element node to receive the inserted child. |
| node | Source-less node to insert. |
| referenceNode | Optional existing child to insert before. |
| std::optional< XMLNode > donner::xml::XMLDocument::nodeAtSourceOffset | ( | std::size_t | offset | ) | const |
Return the deepest parsed XML node whose current source range contains offset.
This is the first source-position lookup primitive used by incremental editing. It resolves node source anchors before comparing offsets, so source edits made through XMLSourceStore are reflected without reparsing the full document.
| offset | Byte offset in the current XML source. |
| ApplySourceEditResult donner::xml::XMLDocument::removeAttribute | ( | XMLNode | node, |
| const XMLQualifiedNameRef & | name ) |
Remove an XML attribute through this document and update owned source text.
This is the DOM-side structured editing entry point for source-backed attribute removals. It removes the serialized attribute through XMLSourceStore, updates the live DOM attribute set, and emits an XMLMutation::Kind::AttributeRemoved mutation.
| node | Element node that owns the attribute. |
| name | Attribute name to remove. |
| ApplySourceEditResult donner::xml::XMLDocument::removeNode | ( | XMLNode | node | ) |
Remove a source-backed XML node through this document.
This applies the source removal through XMLSourceStore, detaches node from the live XML tree, and emits an XMLMutation::Kind::NodeRemoved mutation.
| node | Node to remove. |
| ApplySourceEditResult donner::xml::XMLDocument::setAttribute | ( | XMLNode | node, |
| const XMLQualifiedNameRef & | name, | ||
| std::string_view | value ) |
Set an XML attribute through this document and update owned source text.
This is the DOM-side structured editing entry point for source-backed attribute writes. It preserves the attribute's existing quote style, escapes value for XML, applies the source change through XMLSourceStore, updates the live DOM attribute, and emits an XMLMutation::Kind::AttributeSet mutation.
| node | Element node that owns the attribute. |
| name | Attribute name to set. |
| value | Raw unescaped attribute value. |
| void donner::xml::XMLDocument::setSource | ( | std::string | source | ) |
Install owned source text for this document.
| source | XML source text to own. |
| std::string_view donner::xml::XMLDocument::source | ( | ) | const |
Return the current XML source text.
Documents created programmatically may not have source text; in that case this returns an empty view.