Documentation ¶
Overview ¶
Package xml2json is an XML to JSON converter
Index ¶
- func Convert(r io.Reader, ps ...plugin) (*bytes.Buffer, error)
- func ExcludeAttributes(attrs []string) *excluder
- func NodePlugin(path string, plugin nodePlugin) nodeFormatter
- func ToArray() *arrayFormatter
- func WithAttrPrefix(prefix string) *attrPrefixer
- func WithContentPrefix(prefix string) *contentPrefixer
- func WithNodes(n ...nodeFormatter) *nodesFormatter
- func WithTypeConverter(ts ...JSType) *customTypeConverter
- type Decoder
- func (dec *Decoder) AddFormatters(formatters []nodeFormatter)
- func (dec *Decoder) Decode(root *Node) error
- func (dec *Decoder) DecodeWithCustomPrefixes(root *Node, contentPrefix string, attributePrefix string) error
- func (dec *Decoder) ExcludeAttributes(attrs []string)
- func (dec *Decoder) SetAttributePrefix(prefix string)
- func (dec *Decoder) SetContentPrefix(prefix string)
- type Encoder
- type JSType
- type Node
- type Nodes
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExcludeAttributes ¶ added in v1.1.1
func ExcludeAttributes(attrs []string) *excluder
ExcludeAttributes excludes some xml attributes, for example, xmlns:xsi, xsi:noNamespaceSchemaLocation
func NodePlugin ¶ added in v1.1.1
func NodePlugin(path string, plugin nodePlugin) nodeFormatter
func WithAttrPrefix ¶ added in v1.1.1
func WithAttrPrefix(prefix string) *attrPrefixer
WithAttrPrefix appends the given prefix to the json output of xml attribute fields to preserve namespaces
func WithContentPrefix ¶ added in v1.1.1
func WithContentPrefix(prefix string) *contentPrefixer
WithContentPrefix appends the given prefix to the json output of xml content fields to preserve namespaces
func WithNodes ¶ added in v1.1.1
func WithNodes(n ...nodeFormatter) *nodesFormatter
WithNodes formats specific nodes
func WithTypeConverter ¶ added in v1.1.1
func WithTypeConverter(ts ...JSType) *customTypeConverter
WithTypeConverter allows customized js type conversion behavior by passing in the desired JSTypes
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
A Decoder reads and decodes XML objects from an input stream.
func NewDecoder ¶
NewDecoder returns a new decoder that reads from r.
func (*Decoder) AddFormatters ¶ added in v1.1.1
func (dec *Decoder) AddFormatters(formatters []nodeFormatter)
func (*Decoder) Decode ¶
Decode reads the next JSON-encoded value from its input and stores it in the value pointed to by v.
func (*Decoder) DecodeWithCustomPrefixes ¶ added in v1.1.0
func (*Decoder) ExcludeAttributes ¶ added in v1.1.1
func (*Decoder) SetAttributePrefix ¶ added in v1.1.0
func (*Decoder) SetContentPrefix ¶ added in v1.1.0
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
An Encoder writes JSON objects to an output stream.
func NewEncoder ¶
NewEncoder returns a new encoder that writes to w.
type JSType ¶ added in v1.1.1
type JSType int
https://cswr.github.io/JsonSchema/spec/basic_types/ JSType is a JavaScript extracted from a string
func Str2JSType ¶ added in v1.1.1
Str2JSType extract a JavaScript type from a string