xml

package module
v0.0.0-...-c96282f Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

README

xml

Go Reference godocs.io Go Report Card

Wrapper around encoding/xml.Decode to facilitate the Inversion of Control pattern and provide a domain object model builder.

The enclosed svg package is a simplistic SVG11 renderer that can parse a DOM from the above. The following elements are (mostly) supported: svg defs use g line rect circle ellipse polyline polygon path clipPath

The svgrender command (xml/svg/cmd) can read either the standard input or the supplied file and render it to svgrender.png.

Documentation

Overview

Package xml contains functions which wrap encoding/xml.Decoder in the standard library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

type Element struct {
	Type       TT                // Node or Content
	Name       xml.Name          // Node name
	Attributes map[string]string // Node attributes
	Content    xml.CharData      // CDATA content
	Parent     *Element          // Parent node
	Children   []*Element        // List of child nodes and contents for this node
}

Element is used to form the tree structure of the Document Object Model.

func (*Element) Copy

func (elt *Element) Copy() *Element

Copy returns a deep copy of this element and its children.

type TT

type TT int

TT represents the element type.

const (
	Node TT = iota
	Content
)

type XMLDecoder

type XMLDecoder struct {
	Decoder      *xml.Decoder
	StartElement func(token xml.StartElement) error
	EndElement   func(token xml.EndElement) error
	CharData     func(token xml.CharData) error
	Comment      func(token xml.Comment) error
	ProcInst     func(token xml.ProcInst) error
	Directive    func(token xml.Directive) error
}

XMLDecoder is a wrapper around xml.Decoder and holds the functions to be called when tokens are encountered. Functions that are left as nil are skipped by Process().

func NewXMLDecoder

func NewXMLDecoder(r io.Reader) *XMLDecoder

NewXMLDecoder creates a new XMLDecoder that will read from the supplied io.Reader.

func (*XMLDecoder) BuildDOM

func (d *XMLDecoder) BuildDOM() (*Element, error)

BuildDOM inserts its own functions into the decoder in order to build the Domain Object Model.

func (*XMLDecoder) Process

func (d *XMLDecoder) Process() error

Process performs the tokenization of the reader data and calls the user supplied functions.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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