treeutils

package
Version: v0.0.2-0...-ad08894 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2018 License: MIT, Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	XMLNamespace   = "http://www.w3.org/XML/1998/namespace"
	XMLNSNamespace = "http://www.w3.org/2000/xmlns/"
)

Variables

View Source
var (
	DefaultNSContext = NSContext{
						// contains filtered or unexported fields
	}

	EmptyNSContext = NSContext{}

	ErrReservedNamespace       = errors.New("disallowed declaration of reserved namespace")
	ErrInvalidDefaultNamespace = errors.New("invalid default namespace declaration")
	ErrTraversalHalted         = errors.New("traversal halted")
)

Functions

func NSDetatch

func NSDetatch(ctx NSContext, el *xmltree.Element) (*xmltree.Element, error)

NSDetatch makes a copy of the passed element, and declares any namespaces in the passed context onto the new element before returning it.

func NSFindIterate

func NSFindIterate(el *xmltree.Element, namespace, tag string, handle NSIterHandler) error

NSFindIterate behaves identically to NSFindIterateCtx, but uses DefaultNSContext as the surrounding context.

func NSFindIterateCtx

func NSFindIterateCtx(ctx NSContext, el *xmltree.Element, namespace, tag string, handle NSIterHandler) error

NSFindIterateCtx conducts a depth-first traversal searching for elements with the specified tag in the specified namespace. It uses the passed NSContext for prefix lookups. For each such element, the passed handler function is invoked. If the handler function returns an error traversal is immediately halted. If the error returned by the handler is ErrTraversalHalted then nil will be returned by NSFindIterate. If any other error is returned by the handler, that error will be returned by NSFindIterate.

func NSFindOne

func NSFindOne(el *xmltree.Element, namespace, tag string) (*xmltree.Element, error)

NSFindOne behaves identically to NSFindOneCtx, but uses DefaultNSContext for context.

func NSFindOneCtx

func NSFindOneCtx(ctx NSContext, el *xmltree.Element, namespace, tag string) (*xmltree.Element, error)

NSFindOneCtx conducts a depth-first search for the specified element. If such an element is found a reference to it is returned.

func NSSelectOne

func NSSelectOne(el *xmltree.Element, namespace, tag string) (*xmltree.Element, error)

NSSelectOne behaves identically to NSSelectOneCtx, but uses DefaultNSContext as the surrounding context.

func NSSelectOneCtx

func NSSelectOneCtx(ctx NSContext, el *xmltree.Element, namespace, tag string) (*xmltree.Element, error)

NSSelectOneCtx conducts a depth-first search for an element with the specified namespace and tag. If such an element is found, a new *xmltree.Element is returned which is a copy of the found element, but with all in-context namespace declarations attached to the element as attributes.

func NSTraverse

func NSTraverse(ctx NSContext, el *xmltree.Element, handle NSIterHandler) error

NSTraverse traverses an element tree, invoking the passed handler for each element in the tree.

func NSUnmarshalElement

func NSUnmarshalElement(ctx NSContext, el *xmltree.Element, v interface{}) error

NSUnmarshalElement unmarshals the passed xmltree Element into the value pointed to by v using encoding/xml in the context of the passed NSContext. If v implements ElementKeeper, SetUnderlyingElement will be called on v with a reference to el.

func TransformExcC14n

func TransformExcC14n(el *xmltree.Element, inclusiveNamespacesPrefixList string) error

TransformExcC14n transforms the passed element into xml-exc-c14n form.

Types

type ElementKeeper

type ElementKeeper interface {
	SetUnderlyingElement(*xmltree.Element)
	UnderlyingElement() *xmltree.Element
}

ElementKeeper should be implemented by types which will be passed to UnmarshalElement, but wish to keep a reference

type ErrUndeclaredNSPrefix

type ErrUndeclaredNSPrefix struct {
	Prefix string
}

func (ErrUndeclaredNSPrefix) Error

func (e ErrUndeclaredNSPrefix) Error() string

type NSContext

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

func NSBuildParentContext

func NSBuildParentContext(el *xmltree.Element) (NSContext, error)

NSBuildParentContext recurses upward from an element in order to build an NSContext for its immediate parent. If the element has no parent DefaultNSContext is returned.

func (NSContext) Copy

func (ctx NSContext) Copy() NSContext

func (NSContext) LookupPrefix

func (ctx NSContext) LookupPrefix(prefix string) (string, error)

LookupPrefix attempts to find a declared namespace for the specified prefix. If the prefix is an empty string this will be the default namespace for this context. If the prefix is undeclared in this context an ErrUndeclaredNSPrefix will be returned.

func (NSContext) Prefixes

func (ctx NSContext) Prefixes() map[string]string

Prefixes returns a copy of this context's prefix map.

func (NSContext) SubContext

func (ctx NSContext) SubContext(el *xmltree.Element) (NSContext, error)

type NSIterHandler

type NSIterHandler func(NSContext, *xmltree.Element) error

NSIterHandler is a function which is invoked with a element and its surrounding NSContext during traversals.

type SortedAttrs

type SortedAttrs []xmltree.Attr

SortedAttrs provides sorting capabilities, compatible with XML C14N, on top of an []xmltree.Attr

func (SortedAttrs) Len

func (a SortedAttrs) Len() int

func (SortedAttrs) Less

func (a SortedAttrs) Less(i, j int) bool

func (SortedAttrs) Swap

func (a SortedAttrs) Swap(i, j int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL