xml

package
v0.0.0-...-3f97f43 Latest Latest
Warning

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

Go to latest
Published: May 28, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(r io.Reader, ps ...plugin) (*bytes.Buffer, error)

Convert converts the given XML document to JSON

func ExcludeAttributes

func ExcludeAttributes(attrs []string) *excluder

ExcludeAttributes excludes some xml attributes, for example, xmlns:xsi, xsi:noNamespaceSchemaLocation

func NodePlugin

func NodePlugin(path string, plugin nodePlugin) nodeFormatter

func ToArray

func ToArray() *arrayFormatter

func WithAttrPrefix

func WithAttrPrefix(prefix string) *attrPrefixer

WithAttrPrefix appends the given prefix to the json output of xml attribute fields to preserve namespaces

func WithContentPrefix

func WithContentPrefix(prefix string) *contentPrefixer

WithContentPrefix appends the given prefix to the json output of xml content fields to preserve namespaces

func WithNodes

func WithNodes(n ...nodeFormatter) *nodesFormatter

WithNodes formats specific nodes

func WithTypeConverter

func WithTypeConverter(ts ...JSType) *customTypeConverter

WithTypeConverter allows customized js type conversion behavior by passing in the desired JSTypes

func WriteXmlJson

func WriteXmlJson(w io.Writer, level int, a ...interface{}) (err error)

func XmlJsonToString

func XmlJsonToString(level int, a ...interface{}) (s string, err error)

Types

type Attr

type Attr struct {
	Space string
	Name  string
	Value string
}

type Decoder

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

A Decoder reads and decodes XML objects from an input stream.

func NewDecoder

func NewDecoder(r io.Reader, plugins ...plugin) *Decoder

NewDecoder returns a new decoder that reads from r.

func (*Decoder) AddFormatters

func (dec *Decoder) AddFormatters(formatters []nodeFormatter)

func (*Decoder) Decode

func (dec *Decoder) Decode(root *Node) error

Decode reads the next JSON-encoded value from its input and stores it in the value pointed to by v.

func (*Decoder) DecodeWithCustomPrefixes

func (dec *Decoder) DecodeWithCustomPrefixes(root *Node, contentPrefix string, attributePrefix string) error

func (*Decoder) ExcludeAttributes

func (dec *Decoder) ExcludeAttributes(attrs []string)

func (*Decoder) SetAttributePrefix

func (dec *Decoder) SetAttributePrefix(prefix string)

func (*Decoder) SetContentPrefix

func (dec *Decoder) SetContentPrefix(prefix string)

type Encoder

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

An Encoder writes JSON objects to an output stream.

func NewEncoder

func NewEncoder(w io.Writer, plugins ...plugin) *Encoder

NewEncoder returns a new encoder that writes to w.

func (*Encoder) Encode

func (enc *Encoder) Encode(root *Node) error

Encode writes the JSON encoding of v to the stream

type JSType

type JSType int

https://cswr.github.io/JsonSchema/spec/basic_types/ JSType is a JavaScript extracted from a string

const (
	Bool JSType = iota
	Int
	Float
	String
	Null
)

func Str2JSType

func Str2JSType(s string) JSType

Str2JSType extract a JavaScript type from a string

type Node

type Node struct {
	Children              map[string]Nodes
	Data                  string
	ChildrenAlwaysAsArray bool
}

Node is a data element on a tree

func (*Node) AddChild

func (n *Node) AddChild(s string, c *Node)

AddChild appends a node to the list of children

func (*Node) GetChild

func (n *Node) GetChild(path string) *Node

GetChild returns child by path if exists. Path looks like "grandparent.parent.child.grandchild"

func (*Node) IsComplex

func (n *Node) IsComplex() bool

IsComplex returns whether it is a complex type (has children)

type Nodes

type Nodes []*Node

Nodes is a list of nodes

type XmlSax

type XmlSax struct {
	Object interface{}
	Level  int

	LevelNames map[int][]string
	LevelAttrs map[int][]Attr

	CallFunc func(interface{}, ...interface{}) interface{}

	Error func(xmlsx *XmlSax, lasterr error)

	StartElement func(xmlsx *XmlSax, space string, name string, attrs ...Attr) (done bool)

	ElemData func(xmlsx *XmlSax, data []byte)

	EndElement func(xmlsx *XmlSax, space string, name string) (done bool)

	OnClose func(xmlsx *XmlSax)

	Eof func(xmlsx *XmlSax)
	// contains filtered or unexported fields
}

func NewXmlSAX

func NewXmlSAX(a ...interface{}) (xmlsx *XmlSax)

func (*XmlSax) Close

func (xmlsx *XmlSax) Close() (err error)

func (*XmlSax) Next

func (xmlsx *XmlSax) Next() (canContinue bool, err error)

Jump to

Keyboard shortcuts

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