etreeutils

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: Apache-2.0 Imports: 6 Imported by: 241

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 (
	EmptyNSContext = NSContext{}

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

Functions

func NSDetatch

func NSDetatch(ctx NSContext, el *etree.Element) (*etree.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 NSFindChildrenIterateCtx

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

NSFindIterateChildrenCtx takes an element and its surrounding context, and iterates the children of that element searching for an element matching the passed namespace and tag. For each such element that is found, handle is invoked with the matched element and its own surrounding context.

func NSFindIterate

func NSFindIterate(el *etree.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 *etree.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 *etree.Element, namespace, tag string) (*etree.Element, error)

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

func NSFindOneChild

func NSFindOneChild(el *etree.Element, namespace, tag string) (*etree.Element, error)

NSFindOneChild behaves identically to NSFindOneChildCtx, but uses DefaultNSContext for context.

func NSFindOneChildCtx

func NSFindOneChildCtx(ctx NSContext, el *etree.Element, namespace, tag string) (*etree.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 NSFindOneCtx

func NSFindOneCtx(ctx NSContext, el *etree.Element, namespace, tag string) (*etree.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 NSIterateChildren

func NSIterateChildren(ctx NSContext, el *etree.Element, handle NSIterHandler) error

NSIterateChildren iterates the children of an element, invoking the passed handler with each direct child of the element, and the context surrounding that child.

func NSSelectOne

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

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

func NSSelectOneCtx

func NSSelectOneCtx(ctx NSContext, el *etree.Element, namespace, tag string) (*etree.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 *etree.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 *etree.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 *etree.Element, v interface{}) error

NSUnmarshalElement unmarshals the passed etree 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 *etree.Element, inclusiveNamespacesPrefixList string, comments bool) error

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

Types

type ElementKeeper

type ElementKeeper interface {
	SetUnderlyingElement(*etree.Element)
	UnderlyingElement() *etree.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 *etree.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 NewDefaultNSContext added in v1.3.0

func NewDefaultNSContext() NSContext

func (NSContext) CheckLimit added in v1.3.0

func (ctx NSContext) CheckLimit() error

CheckLimit checks the traversal limit before calling the handler function

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 *etree.Element) (NSContext, error)

type NSIterHandler

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

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

type SortedAttrs

type SortedAttrs []etree.Attr

SortedAttrs provides sorting capabilities, compatible with XML C14N, on top of an []etree.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
y or Y : Canonical URL