xtree

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Prepare

func Prepare(n *Node) error

Prepare traverses the xtree rooted at n and sets signature and hash for all nodes.

func TextString

func TextString(n *Node) (string, error)

TextString is a helper function to quickly get string representation of the node tree in text format.

func XMLString

func XMLString(n *Node) (string, error)

XMLString is a helper function to quickly get string representation of the node tree in xml format.

Types

type Node

type Node struct {
	Type              NodeType
	Parent            *Node
	FirstChild        *Node
	NextSibling       *Node
	PrevSiblingCyclic *Node
	Name              []byte
	Value             []byte
	Hash              []byte
	Signature         []byte
}

Node represents node of the xtree.

func NewAttribute

func NewAttribute(name []byte, value []byte) *Node

NewAttribute creates new node with Attribute type.

func NewCData

func NewCData(value []byte) *Node

NewCData creates new node with CData type.

func NewComment

func NewComment(value []byte) *Node

NewComment creates new node with Comment type.

func NewData

func NewData(value []byte) *Node

NewData creates new node with Data type.

func NewDeclaration

func NewDeclaration() *Node

NewDeclaration creates new node with Declaration type.

func NewDirectory

func NewDirectory(name []byte) *Node

NewDirectory creates new node with Directory type.

func NewDoctype

func NewDoctype(value []byte) *Node

NewDoctype creates new node with Doctype type.

func NewDocument

func NewDocument(name []byte) *Node

NewDocument creates new node with Document type.

func NewElement

func NewElement(name []byte) *Node

NewElement creates new node with Element type.

func NewNode

func NewNode(t NodeType) *Node

NewNode creates new node of type t.

func NewNotXML

func NewNotXML(name []byte, value []byte) *Node

NewNotXML creates new node with NotXML type.

func NewProcInstr

func NewProcInstr(name []byte, value []byte) *Node

NewProcInstr creates new node with ProcInstr type.

func (*Node) AppendChild

func (n *Node) AppendChild(child *Node) *Node

AppendChild appends child node to the node.

func (*Node) CalculateHash

func (n *Node) CalculateHash(h hash.Hash) error

CalculateHash sets hash value of the node.

func (*Node) CalculateSignature

func (n *Node) CalculateSignature()

CalculateSignature sets signature value of the node.

func (*Node) Children

func (n *Node) Children() []*Node

Children returns list of immediate children of the node.

func (*Node) LastChild

func (n *Node) LastChild() *Node

LastChild returns last child of the node.

func (*Node) PrevSibling

func (n *Node) PrevSibling() *Node

PrevSibling returns previous sibling of the node.

func (*Node) Remove

func (n *Node) Remove()

Remove removes node from the xtree.

func (Node) String

func (n Node) String() string

Implements stringer.

type NodeType

type NodeType int

NodeType is describing possible node types.

const (
	// Node is not xml file.
	NotXML NodeType = iota
	// A directory node. Name is same as directory name. Value is empty.
	Directory
	// A document node. If result of directory parsing name is same as the filename otherwise it's empty. Value is empty.
	Document
	// An element node. Name contains element name. Value contains text of first data node.
	Element
	// An attribute node. Name contains attribute name. Value contains attribute value.
	Attribute
	// A data node. Name is empty. Value contains text data.
	Data
	// A CDATA node. Name is empty. Value contains text data.
	CData
	// A comment node. Name is empty. Value contains comment text.
	Comment
	// A declaration node. Name and value are empty. Declaration parameters (version, encoding and standalone) are in node attributes.
	Declaration
	// A DOCTYPE node. Name is empty. Value contains DOCTYPE text.
	Doctype
	// A ProcInstr node. Name contains target. Value contains instructions.
	ProcInstr
)

NodeType values.

func (NodeType) Signature

func (nt NodeType) Signature() []byte

Signature returns byte representation of the signature.

func (NodeType) String

func (i NodeType) String() string

type Stack

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

Stack is auxiliary data structure for iterative xtree traversal.

func (*Stack) Empty

func (s *Stack) Empty()

Empty clears stack contents.

func (*Stack) Get

func (s *Stack) Get() []*Node

Get returns stack as slice of nodes without removing them.

func (*Stack) IsEmpty

func (s *Stack) IsEmpty() bool

IsEmpty returns true if stack is empty.

func (*Stack) Len

func (s *Stack) Len() int

Len counts number of items on the stack.

func (*Stack) Peek

func (s *Stack) Peek() *Node

Peek returns node at the top of the stack without removing it.

func (*Stack) Pop

func (s *Stack) Pop() (*Node, bool)

Pop removes node from the top of the stack.

func (*Stack) Push

func (s *Stack) Push(i *Node) bool

Push pushes node to the top of the stack.

type TextEncoder

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

TextEncoder knows how to encode node tree as text format suitable for command line output.

func NewTextEncoder

func NewTextEncoder(w io.Writer) *TextEncoder

NewTextEncoder creates new textual encoder that writes text into the writer.

func (*TextEncoder) Encode

func (enc *TextEncoder) Encode(n *Node) error

Encode writes node tree rooted at n to the stream.

type XMLEncoder

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

XMLEncoder knows how to encode node tree to XML format.

func NewXMLEncoder

func NewXMLEncoder(w io.Writer) *XMLEncoder

NewXMLEncoder creates new XMLEncoder that writes xml into the writer.

func (*XMLEncoder) Encode

func (enc *XMLEncoder) Encode(n *Node) error

Encode writes node tree rooted at n to the stream.

func (*XMLEncoder) Indent

func (enc *XMLEncoder) Indent(indent string)

Indent sets the encoder to generate XML in which each element begins on a new indented line that starts with one or more copies of indent according to the nesting depth.

Jump to

Keyboard shortcuts

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