tree

package
v0.0.0-...-97928f7 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2021 License: MIT Imports: 6 Imported by: 46

Documentation

Index

Constants

View Source
const (
	True  = "true"
	False = "false"
)

Boolean strings

View Source
const XMLSpace = "http://www.w3.org/XML/1998/namespace"

XMLSpace is the W3C XML namespace

Variables

This section is empty.

Functions

func GetAttrValOrEmpty

func GetAttrValOrEmpty(n Elem, local, space string) string

GetAttrValOrEmpty is like GetAttributeVal, except it returns an empty string if the attribute is not found instead of false.

func GetAttribute

func GetAttribute(n Elem, local, space string) (xml.Attr, bool)

GetAttribute is a convenience function for getting the specified attribute from an element. false is returned if the attribute is not found.

func GetAttributeVal

func GetAttributeVal(n Elem, local, space string) (string, bool)

GetAttributeVal is like GetAttribute, except it returns the attribute's value.

Types

type Bool

type Bool bool

Bool is a boolean XPath type

func (Bool) Bool

func (b Bool) Bool() Bool

Bool satisfies the HasBool interface for Bool's

func (Bool) Num

func (b Bool) Num() Num

Num satisfies the HasNum interface for Bool's

func (Bool) String

func (b Bool) String() string

ResValue satisfies the Res interface for Bool

type Ctx

type Ctx struct {
	NodeSet
	Pos  int
	Size int
}

Ctx represents the current context position, size, node, and the current filtered result

type Elem

type Elem interface {
	Node
	//GetChildren returns the elements children.
	GetChildren() []Node
	//GetAttrs returns the attributes of the element
	GetAttrs() []Node
}

Elem is a XPath result that is an element node

type Fn

type Fn func(c Ctx, args ...Result) (Result, error)

Fn is a XPath function, written in Go

type IsBool

type IsBool interface {
	Bool() Bool
}

IsBool is used for the XPath boolean function. It turns the data type to a bool.

type IsNum

type IsNum interface {
	Num() Num
}

IsNum is used for the XPath number function. It turns the data type to a number.

type LastArgOpt

type LastArgOpt int

LastArgOpt sets whether the last argument in a function is optional, variadic, or neither

const (
	None LastArgOpt = iota
	Optional
	Variadic
)

LastArgOpt options

type NS

type NS struct {
	xml.Attr
	Parent Elem
	NodePos
	NodeType
}

NS is a namespace node.

func BuildNS

func BuildNS(t Elem) (ret []NS)

BuildNS resolves all the namespace nodes of the element and returns them

func (NS) GetParent

func (ns NS) GetParent() Elem

GetParent returns the parent node of the namespace.

func (NS) GetToken

func (ns NS) GetToken() xml.Token

GetToken returns the xml.Token representation of the namespace.

func (NS) ResValue

func (ns NS) ResValue() string

ResValue returns the string value of the namespace

type NSBuilder

type NSBuilder struct {
	NS map[xml.Name]string
}

NSBuilder is a helper-struct for satisfying the NSElem interface

func (NSBuilder) GetNS

func (ns NSBuilder) GetNS() map[xml.Name]string

GetNS returns the namespaces found on the current element. It should not be confused with BuildNS, which actually resolves the namespace nodes.

type NSElem

type NSElem interface {
	Elem
	GetNS() map[xml.Name]string
}

NSElem is a node that keeps track of namespaces.

type Node

type Node interface {
	//ResValue prints the node's string value
	ResValue() string
	//Pos returns the node's position in the document order
	Pos() int
	//GetToken returns the xml.Token representation of the node
	GetToken() xml.Token
	//GetParent returns the parent node, which will always be an XML element
	GetParent() Elem
	//GetNodeType returns the node's type
	GetNodeType() NodeType
}

Node is a XPath result that is a node except elements

func FindNodeByPos

func FindNodeByPos(n Node, pos int) Node

FindNodeByPos finds a node from the given position. Returns nil if the node is not found.

type NodePos

type NodePos int

NodePos is a helper for representing the node's document order

func (NodePos) Pos

func (n NodePos) Pos() int

Pos returns the node's document order position

type NodeSet

type NodeSet []Node

NodeSet is a node-set XPath type

func (NodeSet) Bool

func (n NodeSet) Bool() Bool

Bool satisfies the HasBool interface for node-set's

func (NodeSet) Num

func (n NodeSet) Num() Num

Num satisfies the HasNum interface for NodeSet's

func (NodeSet) String

func (n NodeSet) String() string

String satisfies the Res interface for NodeSet

type NodeType

type NodeType int

NodeType is a safer way to determine a node's type than type assertions.

const (
	NtAttr NodeType = iota
	NtChd
	NtComm
	NtElem
	NtNs
	NtRoot
	NtPi
)

These are all the possible node types

func (NodeType) GetNodeType

func (t NodeType) GetNodeType() NodeType

GetNodeType returns the node's type.

type Num

type Num float64

Num is a number XPath type

func GetNodeNum

func GetNodeNum(n Node) Num

GetNodeNum converts the node to a string-value and to a number

func (Num) Bool

func (n Num) Bool() Bool

Bool satisfies the HasBool interface for Num's

func (Num) Num

func (n Num) Num() Num

Num satisfies the HasNum interface for Num's

func (Num) String

func (n Num) String() string

ResValue satisfies the Res interface for Num

type Result

type Result interface {
	fmt.Stringer
}

Result is used for all data types.

type String

type String string

String is string XPath type

func (String) Bool

func (s String) Bool() Bool

Bool satisfies the HasBool interface for String's

func (String) Num

func (s String) Num() Num

Num satisfies the HasNum interface for String's

func (String) String

func (s String) String() string

ResValue satisfies the Res interface for String

type Wrap

type Wrap struct {
	Fn Fn
	//NArgs represents the number of arguments to the XPath function.  -1 represents a single optional argument
	NArgs      int
	LastArgOpt LastArgOpt
}

Wrap interfaces XPath function calls with Go

func (Wrap) Call

func (w Wrap) Call(c Ctx, args ...Result) (Result, error)

Call checks the arguments and calls Fn if they are valid

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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