dom

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package dom provides methods and structs to construct and manipulate a simple Document Object Model

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attributes

type Attributes map[string]string

Attributes of an Element node

func (Attributes) BoolD

func (a Attributes) BoolD(name string, defaultv bool) bool

BoolD retrieves the attribute [name]. Returns [defaultv] if not found

func (Attributes) FirstAttr

func (a Attributes) FirstAttr(name string, names ...string) string

FirstAttr returns the value of the first attibute that is found (if the name matches)

func (Attributes) HasAttr

func (a Attributes) HasAttr(name string, names ...string) bool

HasAttr returns true if one of the attributes is found

func (Attributes) IntD

func (a Attributes) IntD(name string, defaultv int) int

IntD retrieves the attribute [name]. Returns [defaultv] if not found

func (Attributes) String

func (a Attributes) String(name string) string

String returns an attribute value

type ElementNode

type ElementNode interface {
	Node
	TagName() string
	Children() []Node
	Attributes() Attributes
	ID() string
	Classes() []string
	Append(n Node)
	SetAttribute(name, value string)
	DeleteAttribute(name string)
	FirstChildAsText() string
	FindChildByID(id string) Node
}

ElementNode is a structured node that may contain attributes and children

func Element

func Element(tagname string, attributes map[string]string, children ...Node) ElementNode

Element creates an element node

type Node

type Node interface {
	Type() NodeType
}

Node is a valid DOM node

func ParseXMLString

func ParseXMLString(xmlstr string) ([]Node, error)

ParseXMLString parses a XLM string.

type NodeType

type NodeType int

NodeType represents an Element/Object or Text

const (
	NodeElement NodeType = iota
	NodeText    NodeType = iota
)

Valid DOM nodes

type TextNode

type TextNode interface {
	Node
	Text() string
}

TextNode is a valid DOM node with a text only content

func Text

func Text(str string) TextNode

Text creates a text node

Jump to

Keyboard shortcuts

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