Documentation ¶
Index ¶
- Constants
- Variables
- type Node
- func CallbackNode(name xml.Name, fn NodeTokenCallback, opts ...NodeOption) *Node
- func ElementNode(name xml.Name, opts ...NodeOption) *Node
- func EndElementEventNode(fn NodeTokenCallback, opts ...NodeOption) *Node
- func HandoffEventNode(fn StateFn, opts ...NodeOption) *Node
- func NewSchema(options ...NodeOption) *Node
- func ProcInstNode(target string, opts ...NodeOption) *Node
- func StartElementEventNode(fn NodeTokenCallback, opts ...NodeOption) *Node
- func TextEventNode(fn NodeTokenCallback, opts ...NodeOption) *Node
- func TextNode(opts ...NodeOption) *Node
- func TokenEventNode(fn NodeTokenCallback, opts ...NodeOption) *Node
- func (n *Node) Append(child *Node) *Node
- func (n *Node) InsertAfter(ref, child *Node) *Node
- func (n *Node) InsertBefore(ref, child *Node) *Node
- func (n *Node) Iter(fn NodeIterFn) (err error)
- func (n *Node) IterReverse(fn NodeIterFn) (err error)
- func (n *Node) ParentElement() (it *Node)
- func (n *Node) Prepend(child *Node) *Node
- type NodeIterFn
- type NodeOption
- type NodeParameters
- type NodeTokenCallback
- type NodeType
- type StateFn
- type StateMachine
Constants ¶
const (
// XMLNS is the XML namespace of this package
XMLNS = "https://github.com/andaru/xmlstream"
)
Variables ¶
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) InsertAfter ¶
func (*Node) InsertBefore ¶
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 ¶
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 ¶
NodeParameters are the schema parameters for a node
type NodeTokenCallback ¶
NodeTokenCallback is the prototype for schema attached callbacks
type StateMachine ¶
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