Donner 0.8.0-pre
Embeddable browser-grade SVG2 engine
Loading...
Searching...
No Matches
donner::xml::XMLDocument Class Reference

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.
Registryregistry ()
 Get the underlying ECS Registry, which holds all data for the document, for advanced use.
std::shared_ptr< RegistrysharedRegistry () 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.
XMLSourceStoresourceStore ()
 Get the mutable source store, or nullptr if this document does not own source text.
const XMLSourceStoresourceStore () const
 Get the immutable source store, or nullptr if this document does not own source text.
std::optional< XMLNodenodeAtSourceOffset (std::size_t offset) const
 Return the deepest parsed XML node whose current source range contains offset.
std::optional< XMLAttributeAtSourceOffsetattributeAtSourceOffset (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.

Detailed Description

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.

See also
XMLNode
Entity Component System (ECS)

Constructor & Destructor Documentation

◆ XMLDocument()

donner::xml::XMLDocument::XMLDocument ( )

Constructor to create an empty XMLDocument.

To load a document from an XML file, use donner::xml::XMLParser.

Member Function Documentation

◆ applySourceEdit()

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.

Parameters
intentSource edit request.

◆ attributeAtSourceOffset()

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.

Parameters
offsetByte offset in the current XML source.

◆ CreateFromRegistry()

XMLDocument donner::xml::XMLDocument::CreateFromRegistry ( std::shared_ptr< Registry > registry)
static

Rehydrate an XMLDocument facade from an internal shared registry.

Parameters
registryShared XML document registry to wrap.

◆ insertNode()

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.

Parameters
parentElement node to receive the inserted child.
nodeSource-less node to insert.
referenceNodeOptional existing child to insert before.

◆ nodeAtSourceOffset()

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.

Parameters
offsetByte offset in the current XML source.

◆ removeAttribute()

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.

Parameters
nodeElement node that owns the attribute.
nameAttribute name to remove.

◆ removeNode()

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.

Parameters
nodeNode to remove.

◆ setAttribute()

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.

Parameters
nodeElement node that owns the attribute.
nameAttribute name to set.
valueRaw unescaped attribute value.

◆ setSource()

void donner::xml::XMLDocument::setSource ( std::string source)

Install owned source text for this document.

Parameters
sourceXML source text to own.

◆ source()

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.


The documentation for this class was generated from the following file: