xml

package
v1.0.36 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package xml provides a bounded, deterministic XML fragment CRDT.

A fragment is an ordered RGA of immutable XML nodes. Editing a node means inserting a replacement and deleting the old node; this deliberately avoids pretending that concurrent attribute writes have a proven merge rule. Node insertions, deletions, duplicate delivery, and out-of-order delivery use the generic list RGA protocol and remain convergent.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidNode     = errors.New("xml: invalid node")
	ErrInvalidDocument = errors.New("xml: invalid XML document")
	ErrResourceLimit   = errors.New("xml: resource limit exceeded")
)

Functions

func MarshalDelta

func MarshalDelta(delta Delta) ([]byte, error)

MarshalDelta returns a canonical fragment delta frame.

func RenderDocument

func RenderDocument(node Node) (string, error)

RenderDocument returns one deterministic XML document. node must be an element because XML documents cannot have text as their root.

Types

type Attribute

type Attribute struct {
	Name  string
	Value string
}

Attribute is one element attribute. Attribute names are ASCII XML names, unique within a node, and stored in canonical lexical order.

type Delta

type Delta = list.Delta

Delta is a joinable fragment mutation.

func UnmarshalDelta

func UnmarshalDelta(data []byte) (Delta, error)

UnmarshalDelta validates one bounded canonical fragment delta frame.

type Fragment

type Fragment struct {
	// contains filtered or unexported fields
}

Fragment is an ordered, collaboratively replicated XML fragment.

func New

func New(replicaID string) (*Fragment, error)

New creates a fragment with the generic list's conservative default limits.

func NewFromSnapshot

func NewFromSnapshot(saved snapshot.Snapshot) (*Fragment, error)

NewFromSnapshot restores a complete fragment snapshot with default limits.

func NewFromSnapshotWithOptions

func NewFromSnapshotWithOptions(saved snapshot.Snapshot, options list.Options) (*Fragment, error)

NewFromSnapshotWithOptions restores a complete fragment snapshot within explicit list retention and decoder limits.

func NewWithOptions

func NewWithOptions(replicaID string, options list.Options) (*Fragment, error)

NewWithOptions creates a fragment with explicit retained-state limits.

func (*Fragment) Append

func (f *Fragment) Append(nodes []Node) (Delta, error)

Append adds nodes after the current visible tail.

func (*Fragment) ApplyDelta

func (f *Fragment) ApplyDelta(delta Delta) error

ApplyDelta integrates one decoded fragment mutation.

func (*Fragment) Delete

func (f *Fragment) Delete(offset, count int) (Delta, error)

Delete removes count visible nodes beginning at offset.

func (*Fragment) Insert

func (f *Fragment) Insert(offset int, nodes []Node) (Delta, error)

Insert adds nodes before visible node offset.

func (*Fragment) MarshalBinary

func (f *Fragment) MarshalBinary() ([]byte, error)

MarshalBinary encodes a canonical complete fragment state frame.

func (*Fragment) Merge

func (f *Fragment) Merge(other *Fragment) error

Merge joins every retained node and deletion from other.

func (*Fragment) Nodes

func (f *Fragment) Nodes() ([]Node, error)

Nodes returns the visible fragment node projection.

func (*Fragment) Positions

func (f *Fragment) Positions() []Position

Positions returns visible stable node IDs in fragment order.

func (*Fragment) RenderFragment

func (f *Fragment) RenderFragment() (string, error)

RenderFragment returns the concatenated XML rendering of visible top-level nodes. A fragment containing multiple elements is intentionally not a full XML document; use RenderDocument for one document root.

func (*Fragment) SnapshotCurrentState

func (f *Fragment) SnapshotCurrentState() (snapshot.Snapshot, error)

SnapshotCurrentState creates an HLC-backed complete fragment snapshot.

func (*Fragment) State

func (f *Fragment) State() crdt.StateSnapshot

State returns a value-free diagnostic summary.

func (*Fragment) UnmarshalBinary

func (f *Fragment) UnmarshalBinary(data []byte) error

UnmarshalBinary validates a complete framed state before replacing f.

type Node

type Node struct {
	Kind       NodeKind
	Name       string
	Attributes []Attribute
	Text       string
	Children   []Node
}

Node is an immutable-by-convention XML value. Insert copies its canonical representation, and Values returns newly decoded values, so callers can safely mutate their own slices after either call.

Namespace prefixes, DTDs, comments, processing instructions, and mixed non-text token classes are intentionally unsupported in v1. Text and child nodes may be mixed inside an element.

func ParseDocument

func ParseDocument(data []byte) (Node, error)

ParseDocument parses one strict, bounded XML document into a node. It rejects directives, comments, processing instructions, namespaces, and extra top-level content so every accepted result has one deterministic v1 representation.

type NodeKind

type NodeKind uint8

NodeKind identifies either an element or a text node.

const (
	ElementNode NodeKind = 1
	TextNode    NodeKind = 2
)

type Position

type Position = crdt.Tag

Position is a stable fragment node identity.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL