xpath

package
v0.0.0-...-2343136 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	XPATH_UNDEFINED   XPathObjectType = 0
	XPATH_NODESET                     = 1
	XPATH_BOOLEAN                     = 2
	XPATH_NUMBER                      = 3
	XPATH_STRING                      = 4
	XPATH_POINT                       = 5
	XPATH_RANGE                       = 6
	XPATH_LOCATIONSET                 = 7
	XPATH_USERS                       = 8
	XPATH_XSLT_TREE                   = 9 // An XSLT value tree, non modifiable
)

Variables

This section is empty.

Functions

func Check

func Check(path string) (err error)

func ValueToXPathObject

func ValueToXPathObject(val interface{}) (ret C.xmlXPathObjectPtr)

Convert an arbitrary value into a C.xmlXPathObjectPtr Unrecognised and nil values are converted to empty node sets.

func XPathObjectToValue

func XPathObjectToValue(obj C.xmlXPathObjectPtr) (result interface{})

Types

type Expression

type Expression struct {
	Ptr *C.xmlXPathCompExpr
	// contains filtered or unexported fields
}

func Compile

func Compile(path string) (expr *Expression)

func (*Expression) Free

func (exp *Expression) Free()

func (*Expression) String

func (exp *Expression) String() string

type VariableScope

type VariableScope interface {
	ResolveVariable(string, string) interface{}
	IsFunctionRegistered(string, string) bool
	ResolveFunction(string, string) XPathFunction
}

This interface exist primarily for the benefit of XSLT processors.

type XPath

type XPath struct {
	ContextPtr *C.xmlXPathContext
	ResultPtr  *C.xmlXPathObject
}

func NewXPath

func NewXPath(docPtr unsafe.Pointer) (xpath *XPath)

func (*XPath) Evaluate

func (xpath *XPath) Evaluate(nodePtr unsafe.Pointer, xpathExpr *Expression) (err error)

Evaluate an XPath. The returned result is stored in the struct. Call ReturnType to discover the type of result, and call one of the ResultAs* functions to return a copy of the result as a particular type.

func (*XPath) EvaluateAsNodeset

func (xpath *XPath) EvaluateAsNodeset(nodePtr unsafe.Pointer, xpathExpr *Expression) (nodes []unsafe.Pointer, err error)

Evaluate an XPath and attempt to consume the result as a nodeset.

func (*XPath) Free

func (xpath *XPath) Free()

func (*XPath) GetContextPosition

func (xpath *XPath) GetContextPosition() (position, size int)

This allows values to saved and restored during processing of a document.

func (*XPath) RegisterNamespace

func (xpath *XPath) RegisterNamespace(prefix, href string) bool

func (*XPath) ResultAsBoolean

func (xpath *XPath) ResultAsBoolean() (val bool, err error)

Coerce the result into a boolean

func (*XPath) ResultAsNodeset

func (xpath *XPath) ResultAsNodeset() (nodes []unsafe.Pointer, err error)

Get the XPath result as a nodeset.

func (*XPath) ResultAsNumber

func (xpath *XPath) ResultAsNumber() (val float64, err error)

Coerce the result into a number

func (*XPath) ResultAsString

func (xpath *XPath) ResultAsString() (val string, err error)

Coerce the result into a string

func (*XPath) ReturnType

func (xpath *XPath) ReturnType() XPathObjectType

Determine the actual return type of the XPath evaluation.

func (*XPath) SetContextPosition

func (xpath *XPath) SetContextPosition(position, size int)

SetContextPosition sets the internal values needed to determine the values of position() and last() for the current context node.

func (*XPath) SetResolver

func (xpath *XPath) SetResolver(v VariableScope)

Add a variable resolver.

type XPathFunction

type XPathFunction func(context VariableScope, args []interface{}) interface{}

type XPathObjectType

type XPathObjectType int

Jump to

Keyboard shortcuts

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