goxpath

package module
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: 7 Imported by: 0

README

goxpath GoDoc Go Report Card

An XPath 1.0 implementation written in Go based on Chris Trenkamp's version. This one does not require the underlying XML representation implement a specific interface.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(a tree.Adapter, n interface{}, w io.Writer) error

Marshal prints the result tree, r, in XML form to w.

func MarshalStr

func MarshalStr(a tree.Adapter, n interface{}) (string, error)

MarshalStr is like Marhal, but returns a string.

func ParseExec

func ParseExec(xpstr string, a tree.Adapter, t interface{}, opts ...FuncOpts) (tree.Result, error)

ParseExec parses the XPath string, xpstr, and runs Exec.

Types

type FuncOpts

type FuncOpts func(*Opts)

FuncOpts is a function wrapper for Opts.

type Opts

type Opts struct {
	NS    map[string]string
	Funcs map[xml.Name]tree.Wrap
	Vars  map[string]tree.Result
}

Opts defines namespace mappings and custom functions for XPath expressions.

type XPathExec

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

XPathExec is the XPath executor, compiled from an XPath string

func MustParse

func MustParse(xp string) XPathExec

MustParse is like Parse, but panics instead of returning an error.

func Parse

func Parse(xp string) (XPathExec, error)

Parse parses the XPath expression, xp, returning an XPath executor.

func (XPathExec) Exec

func (xp XPathExec) Exec(a tree.Adapter, t interface{}, opts ...FuncOpts) (tree.Result, error)

Exec executes the XPath expression, xp, against the tree, t, with the namespace mappings, ns, and returns the result as a stringer. The adapter 'a' is used to adapt the underlying XML representation to xpath needs.

func (XPathExec) ExecBool

func (xp XPathExec) ExecBool(a tree.Adapter, t interface{}, opts ...FuncOpts) (bool, error)

ExecBool is like Exec, except it will attempt to convert the result to its boolean value.

func (XPathExec) ExecNode

func (xp XPathExec) ExecNode(a tree.Adapter, t interface{}, opts ...FuncOpts) (tree.NodeSet, error)

ExecNode is like Exec, except it will attempt to return the result as a node-set.

func (XPathExec) ExecNum

func (xp XPathExec) ExecNum(a tree.Adapter, t interface{}, opts ...FuncOpts) (float64, error)

ExecNum is like Exec, except it will attempt to convert the result to its number value.

func (XPathExec) MustExec

func (xp XPathExec) MustExec(a tree.Adapter, t interface{}, opts ...FuncOpts) tree.Result

MustExec is like Exec, but panics instead of returning an error.

Directories

Path Synopsis
cmd
internal
treeimpl

Jump to

Keyboard shortcuts

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