xml

package
v0.0.0-...-86643de Latest Latest
Warning

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

Go to latest
Published: May 10, 2019 License: BSD-2-Clause Imports: 7 Imported by: 4

Documentation

Overview

A codec for handling simple XML encoding and decoding.

Simple XML is a subset of XML that keeps the data descriptions simple, yet as powerful and flexible as JSON.

Simple XML

A single object looks like this:

<object>
  <field1>value</field1>
  <field2>value</field2>
  <field3>value</field3>
</object>

Where the "object" is literal, and the "field*" elements would be your field names.

A collection of objects looks like this:

<objects>
  <object>
    <field1>value</field1>
    <field2>value</field2>
    <field3>value</field3>
  </object>
  <object>
    <field1>value</field1>
    <field2>value</field2>
    <field3>value</field3>
  </object>
  <object>
    <field1>value</field1>
    <field2>value</field2>
    <field3>value</field3>
  </object>
</objects>

Where the "objects" and "object" tags are literal, and the "field*" elements would be your field names.

Simple XML supports nesting objects inside each other:

<object>
  <field1>value</field1>
  <field2>
      <subfield1>value</subfield1>
      <subfield2>value</subfield2>
      <subfield3>value</subfield3>
  </field2>
</object>

All values are treated as strings unless a 'type' attribute is applied to the field. Acceptable types values are:

- int (integer) - uint (unsigned integer) - float (floating point number) - bool (boolean; true or false) - string (string - the default)

Index

Constants

View Source
const (
	OptionIncludeTypeAttributes string = "types"
)

Variables

View Source
var (
	Indentation                               string = "  "
	XMLDeclaration                            string = "<?xml version=\"1.0\"?>"
	XMLTagFormat                              string = "<%s>"
	XMLClosingTagFormat                       string = "</%s>"
	XMLElementFormat                          string = "<%s>%s</%s>"
	XMLElementFormatIndented                  string = "<%s>\n%s%s\n</%s>"
	XMLElementWithTypeAttributeFormat         string = "<%s type=\"%s\">%s</%s>"
	XMLElementWithTypeAttributeFormatIndented string = "<%s type=\"%s\">\n%s%s\n</%s>"
	XMLObjectElementName                      string = "object"
	XMLObjectsElementName                     string = "objects"
)

Functions

This section is empty.

Types

type InvalidUnmarshalError

type InvalidUnmarshalError struct {
	Type reflect.Type
}

An InvalidUnmarshalError describes an invalid argument passed to Unmarshal. (The argument to Unmarshal must be a non-nil pointer.)

func (*InvalidUnmarshalError) Error

func (e *InvalidUnmarshalError) Error() string

type SimpleXmlCodec

type SimpleXmlCodec struct{}

SimpleXmlCodec converts objects to and from simple XML.

func (*SimpleXmlCodec) CanMarshalWithCallback

func (c *SimpleXmlCodec) CanMarshalWithCallback() bool

CanMarshalWithCallback indicates whether this codec is capable of marshalling a response with a callback parameter.

func (*SimpleXmlCodec) ContentType

func (c *SimpleXmlCodec) ContentType() string

ContentType gets the content type that this codec handles.

func (*SimpleXmlCodec) ContentTypeSupported

func (c *SimpleXmlCodec) ContentTypeSupported(contentType string) bool

func (*SimpleXmlCodec) FileExtension

func (c *SimpleXmlCodec) FileExtension() string

FileExtension returns the file extension by which this codec is represented.

func (*SimpleXmlCodec) Marshal

func (c *SimpleXmlCodec) Marshal(object interface{}, options map[string]interface{}) ([]byte, error)

Marshal converts an object to a []byte representation. You can optionally pass additional arguments to further customize this call.

func (*SimpleXmlCodec) Unmarshal

func (c *SimpleXmlCodec) Unmarshal(data []byte, obj interface{}) error

Unmarshal converts a []byte representation into an object.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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