xml

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Root = iota
	Tag
	Text
	Comment
	ProcInst
	Directive
)

Possible return values of OutType().

Variables

View Source
var NodeType = reflect.TypeOf([]Node{}).Elem()

Functions

func WriteNode

func WriteNode(w io.Writer, n Node) (int, error)

func WriteNodeAsString

func WriteNodeAsString(n Node) (string, error)

Types

type Decoder

type Decoder struct{}

func (*Decoder) InType

func (d *Decoder) InType() reflect.Type

func (*Decoder) Materialize

func (d *Decoder) Materialize() func(input interface{}) interface{}

func (*Decoder) OutType

func (d *Decoder) OutType() reflect.Type

type Encoder

type Encoder struct{}

func (*Encoder) InType

func (d *Encoder) InType() reflect.Type

func (*Encoder) Materialize

func (d *Encoder) Materialize() func(input interface{}) interface{}

func (*Encoder) OutType

func (d *Encoder) OutType() reflect.Type

type Node

type Node interface {
	// Parent of the current node. Nil for root node.
	Parent() Node

	// Tag name of tag nodes of the form <tagname>...</tagname>. Empty for
	// other node types.
	TagName() string

	// Attributes of tag nodes. Nil for other node types.
	Attr() []*encXml.Attr

	// Child nodes of root and tag nodes. Nil for other node types.
	Children() []Node

	// Text data of text nodes. Empty for other node types.
	Text() string

	// Comment data of comments of the form <!--comment-->. Does not include the
	// <!-- and --> markers. Empty for other node types.
	Comment() string

	// Target of processing instructions of the form <?target inst?>.
	// Empty for other node types.
	Target() string

	// Instruction of processing instructions of the form <?target inst?>.
	// Empty for other node types.
	Inst() string

	// Directive of the form <!directive>. Does not include the <! and >
	// markers. Empty for other node types.
	Directive() string

	// OutType of this node. Returns one of: Root, Tag, Text, Comment, ProcInst
	// or Directive.
	Type() int
}

Represents a single XML node. Can be one of: Root, Tag, Text, Comment, ProcInst or Directive.

String methods return empty strings when called on a non-relevant node. For example, calling TagName() on a Text node or vise versa. The Children() method returns nil for non Tag or Root nodes. The Attr() method returns nil for non Tag nodes.

Parent node is nil only in Root.

func ReadNode

func ReadNode(r io.Reader) (Node, error)

Reads all XML data from the given reader and stores it in a root node.

func ReadNodeFromString

func ReadNodeFromString(input string) (Node, error)

Jump to

Keyboard shortcuts

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