xmlstream

package module
v0.0.0-...-55515bd Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2018 License: Apache-2.0 Imports: 5 Imported by: 1

README

travis-ci GoDoc

xmlstream

The xmlstream package provides Golang libraries for building event driven XML stream processors, such as XMPP and NETCONF stream processing.

Schema are constructed as a tree of *xmlstream.Node, and a state machine xmlstream.StateMachine is provided. A parser object combining the XML decoder with traversal of the schema tree via the state machine is not included here, but can be found in a user package, https://github.com/andaru/netconf/schema.

Documentation

Index

Constants

View Source
const (
	// XMLNS is the XML namespace of this package
	XMLNS = "https://github.com/andaru/xmlstream"
)

Variables

View Source
var (
	// CBTokenize is the callback called during tokenization.
	CBTokenize = xml.Name{Space: XMLNS, Local: "callback-tokenize"}
	// CBStartElement is the callback called during tokenization.
	CBStartElement = xml.Name{Space: XMLNS, Local: "callback-se"}
	// CBEndElement is the callback called at element end.
	CBEndElement = xml.Name{Space: XMLNS, Local: "callback-ee"}
	// CBHandoff denotes the node option which calls StateFn for handoff.
	CBHandoff = xml.Name{Space: XMLNS, Local: "callback-handoff"}
	// CBText denotes the callback called for chardata/text elements.
	CBText = xml.Name{Space: XMLNS, Local: "callback-cd"}
	// CBSEOccurs denotes the callback called for constraint counts
	// when an element occurs.
	CBSEOccurs = xml.Name{Space: XMLNS, Local: "callback-se:occurs"}
)

Functions

This section is empty.

Types

type Node

type Node struct {
	Parent, Child    *Node
	NextSib, PrevSib *Node
	Opt              *nodeOptions
	Status           *nodeData
	T                NodeType
	Name             xml.Name
	Value            interface{}

	Validator NodeTokenCallback
}

Node is a node forming a schema tree

func CallbackNode

func CallbackNode(name xml.Name, fn NodeTokenCallback, opts ...NodeOption) *Node

CallbackNode returns a new callback schema node.

func ElementNode

func ElementNode(name xml.Name, opts ...NodeOption) *Node

ElementNode returns a new schema node for matching XML elements.

func EndElementEventNode

func EndElementEventNode(fn NodeTokenCallback, opts ...NodeOption) *Node

EndElementEventNode returns a callback node which will be executed when its parent node ends (i.e., <foo>'s ending </foo> element is seen) as a token.

func HandoffEventNode

func HandoffEventNode(fn StateFn, opts ...NodeOption) *Node

HandoffEventNode returns a StateFn callback node which will be executed when it is found in a parent prior to the next XML token being read.

func NewSchema

func NewSchema(options ...NodeOption) *Node

NewSchema returns a new schema for parsing XML streams configured with supplied options.

func ProcInstNode

func ProcInstNode(target string, opts ...NodeOption) *Node

ProcInstNode returns a new schema node for matching XML processing instructions.

func StartElementEventNode

func StartElementEventNode(fn NodeTokenCallback, opts ...NodeOption) *Node

StartElementEventNode returns a new callback node which will be executed when its parent node is matched during StartElement processing.

func TextEventNode

func TextEventNode(fn NodeTokenCallback, opts ...NodeOption) *Node

TextEventNode returns a callback node which will be executed when parent TextNode is tokenized.

func TextNode

func TextNode(opts ...NodeOption) *Node

TextNode returns a new schema node for matching text (character data) nodes.

func TokenEventNode

func TokenEventNode(fn NodeTokenCallback, opts ...NodeOption) *Node

TokenEventNode returns a new callback when the token is read, prior to any specific node type callback such as StartElementEventNode being called.

func (*Node) Append

func (n *Node) Append(child *Node) *Node

func (*Node) InsertAfter

func (n *Node) InsertAfter(ref, child *Node) *Node

func (*Node) InsertBefore

func (n *Node) InsertBefore(ref, child *Node) *Node

func (*Node) Iter

func (n *Node) Iter(fn NodeIterFn) (err error)

func (*Node) IterReverse

func (n *Node) IterReverse(fn NodeIterFn) (err error)

func (*Node) ParentElement

func (n *Node) ParentElement() (it *Node)

func (*Node) Prepend

func (n *Node) Prepend(child *Node) *Node

type NodeIterFn

type NodeIterFn func(*Node) error

NodeIterFn is the prototype for node iterators

type NodeOption

type NodeOption func(*Node)

NodeOption is a Node constructor option for setting schema options

func WithMaxOccurs

func WithMaxOccurs(n int) NodeOption

WithMaxOccurs sets the maximum number of times the node may be expressed in input matching the schema. Use 0 for unlimited.

func WithMinOccurs

func WithMinOccurs(n int) NodeOption

WithMinOccurs sets the minimum number of times the node must be expressed in input matching the schema. Use 0 to indicate the node is optional.

func WithParent

func WithParent(parent *Node) NodeOption

WithParent sets the node's parent at construction time. Note that this may be over-written by any further mutations to the node.

func WithValidator

func WithValidator(validator NodeTokenCallback) NodeOption

type NodeParameters

type NodeParameters interface {
	MinOccurs() int
	MaxOccurs() int
}

NodeParameters are the schema parameters for a node

type NodeTokenCallback

type NodeTokenCallback func(context.Context, *Node, xml.Token)

NodeTokenCallback is the prototype for schema attached callbacks

type NodeType

type NodeType int

NodeType is the schema node type

const (
	NodeTypeRoot NodeType = iota
	NodeTypeElement
	NodeTypeText
	NodeTypeProcInst
	NodeTypeCB
)

func (NodeType) Format

func (t NodeType) Format(f fmt.State, _ rune)

type StateFn

type StateFn func(context.Context, *StateMachine) StateFn

func BailWithError

func BailWithError(err error) StateFn

func IgnoreEOF

func IgnoreEOF(ctx context.Context, sm *StateMachine) StateFn

type StateMachine

type StateMachine struct {
	Begin StateFn
	End   StateFn
	Error error
}

The state machine is used to trigger validation and processing of XML input for parsing and data extraction purposes.

func New

func New(begin StateFn) *StateMachine

func (*StateMachine) Run

func (sm *StateMachine) Run(ctx context.Context) error

Jump to

Keyboard shortcuts

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