tree

package
v0.0.0-...-c3cacf9 Latest Latest
Warning

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

Go to latest
Published: May 16, 2019 License: MIT Imports: 5 Imported by: 0

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 FindAttributeForElement

func FindAttributeForElement(a Adapter, node interface{}, lname, space string) (xml.Attr, bool)

FindAttributeForElement iuses ForEachAttr to find the requested attribute

Types

type Adapter

type Adapter interface {
	// Returns the type of the node
	GetNodeType(interface{}) NodeType
	// Returns the parent node of the given node
	GetParent(interface{}) interface{}
	// Returns the position of the node within the document. This is
	// used to order nodes within nodesets
	NodePos(interface{}) int
	// The input is a pointer to an element node. The call should build
	// the namespace of the nodes, and return an array of namespace
	// objects (of type NtNs)
	GetNamespaces(interface{}) []interface{}

	// GetElementName should return the name of the element
	GetElementName(interface{}) xml.Name

	// The input is an attribute. This must return the attribute token
	GetAttrTok(interface{}) xml.Attr
	// The input in a namespace object. This must return a namespace attribute
	GetNamespaceTok(interface{}) xml.Attr
	// The input is an element. It should return an element token
	GetElemTok(interface{}) xml.StartElement
	// The input is a processing instruction. It should return a ProcInst token
	GetProcInstTok(interface{}) xml.ProcInst
	// The input is chardata. It should return a chardata token
	GetCharDataTok(interface{}) xml.CharData
	// The input is a comment. It should return a comment token
	GetCommentTok(interface{}) xml.Comment

	// If the node is an element, iterate attributes of element and call
	// the func with the attribute, and a pointer to the attribute node
	ForEachAttr(interface{}, func(xml.Attr, interface{}))
	// If the node is an element, iterate direct children of the node,
	// and call func with a pointer to each child
	ForEachChild(interface{}, func(interface{}))

	// NewNodeSet must return a new nodeset implementation containing the given nodes
	NewNodeSet([]interface{}) NodeSet
	// StringValue must return the string value of the node
	StringValue(interface{}) string
}

Adapter adapts an XML tree representation to xpath. The requirements for the underlying XML implementation is minimal:

  • The XML implementation must have consistent pointers for its nodes, that is, if two interface{} values are passed to the functions of the adapter interface, those two must point to the same backend node if and only if the interface{} values are equal.
  • The underlying XML implementation must have a way of identifying positions of nodes in a unique way. There must be only one node for any node position. Node positions are not required to be consecutive.

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 Fn

type Fn func(a Adapter, 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 NodeSet

type NodeSet interface {
	GetNodes() []interface{}
	String() string
	Bool() Bool
	Num() Num
	Sort()
	Unique()
}

NodeSet is a node-set XPath type

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

type Num

type Num float64

Num is a number XPath type

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(a Adapter, c Ctx, args ...Result) (Result, error)

Call checks the arguments and calls Fn if they are valid

Jump to

Keyboard shortcuts

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