xmllib

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2023 License: MIT Imports: 15 Imported by: 0

README

xmllib - A heavly modified version of go-xml2json

This is based on https://github.com/basgys/goxml2json with lots of modifications.

Documentation

Overview

Package xmllib is an XML and JSON processing and comparison library

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

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

Convert converts the given XML document to JSON

func ConvertXML

func ConvertXML(r io.Reader, cfg CfgType) (*bytes.Buffer, error)

Convert converts the given XML document to JSON

func Exists

func Exists(name string) bool

Exists return true if the file, specified by 'name', exists

func Fopen

func Fopen(fn string, mode string) (file *os.File, err error)

OK

func KeysFromMap

func KeysFromMap(a interface{}) (keys []string)

OK test+ KeysFromMap returns an array of keys from a map.

func SVar

func SVar(v interface{}) string

SVar convert a variable to it's JSON representation and return

func SVarI

func SVarI(v interface{}) string

SVarI convert a variable to it's JSON representation with indendted JSON

Types

type AttrToValueType

type AttrToValueType struct {
	TagName  string `json:"TagName"`
	AttrName string `json:"AttrName"`
	ValName  string `json:"ValName"`
}

type CfgType

type CfgType struct {
	AttrsToValue []AttrToValueType `json:"AttrsToValue"`
	ValueToAttr  []ValueToAttrType `json:"ValueToAttr"`
	NoSort       []NoSortType      `json:"NoSort"`
	// contains filtered or unexported fields
}

func ReadCfg

func ReadCfg(fn string) (cfg CfgType)

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) *Decoder

NewDecoder returns a new decoder that reads from r.

func (*Decoder) Decode

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

func (*Decoder) DecodeWithCustomPrefixes

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

xyzzy - deptricate this

func (*Decoder) SetAttributePrefix

func (dec *Decoder) SetAttributePrefix(prefix string) *Decoder

func (*Decoder) SetContentPrefix

func (dec *Decoder) SetContentPrefix(prefix string) *Decoder

func (*Decoder) SetCustomPrefixes

func (dec *Decoder) SetCustomPrefixes(att, cont string) *Decoder

type Element

type Element struct {
	Parent *Element
	Self   *Node
	Label  string
}

type Encoder

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

An Encoder writes JSON objects to an output stream.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new encoder that writes to w.

func (*Encoder) CustomPrefixesOption

func (enc *Encoder) CustomPrefixesOption(contentPrefix string, attributePrefix string) *Encoder

func (*Encoder) Encode

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

Encode writes the JSON encoding of v to the stream

func (*Encoder) IndentOption

func (enc *Encoder) IndentOption(s string) *Encoder

func (*Encoder) OutputFormatOption

func (enc *Encoder) OutputFormatOption(s string) *Encoder

func (*Encoder) SetAttributePrefix

func (enc *Encoder) SetAttributePrefix(prefix string)

func (*Encoder) SetContentPrefix

func (enc *Encoder) SetContentPrefix(prefix string)

type NoSortType

type NoSortType struct {
	TagName string `json:"TagName"`
}

type Node

type Node struct {
	Data     string
	NType    NodeType
	Children map[string]NodeList
}

Node is a data element on a tree

func ReadXMLAsNode

func ReadXMLAsNode(r io.Reader) (root *Node, err error)

PJS - ReadXMLAsNode reads a source of XML and returns the Node tree

func (*Node) AddChild

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

AddChild appends a node to the list of children

func (*Node) HasChildren

func (curNode *Node) HasChildren() bool

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

type NodeList

type NodeList []*Node

NodeList is a list of nodes

type NodeType

type NodeType int
const (
	RootNode NodeType = 0
	AttrNode NodeType = 1
	ValNode  NodeType = 2
)

func (NodeType) String

func (nt NodeType) String() string

type ValueToAttrType

type ValueToAttrType struct {
	TagName  string `json:"TagName"`
	AttrName string `json:"AttrName"`
}

Jump to

Keyboard shortcuts

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