Documentation ¶
Overview ¶
Package json2xml converts a JSON structure to XML.
json2xml wraps each type within xml tags named after the type. For example:-
An object is wrapped in `<object></object>`<br /> An array is wrapped in `<array></array>`<br /> A boolean is wrapped in `<boolean></boolean>` , with either "true" or "false" as chardata<br /> A number is wrapped in `<number></number>`<br /> A string is wrapped in `<string></string>`<br /> A null becomes `<null></null>` , with no chardata
When a type is a member of an object, the name of the key becomes an attribute on the type tag, for example: -
{ "Location": { "Longitude": -1.8262, "Latitude": 51.1789 } }
...becomes...
`<object>
<object name="Location"> <number name="Longitude">-1.8262</number> <number name="Latitude">51.1789</number> </object>
</object>`
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidKey = errors.New("invalid key type") ErrUnknownToken = errors.New("unknown token type") ErrInvalidToken = errors.New("invalid token") )
Errors
Functions ¶
func Convert ¶
func Convert(j JSONDecoder, x XMLEncoder) error
Convert converts JSON and sends it to the given XML encoder
Types ¶
type Converter ¶
type Converter struct {
// contains filtered or unexported fields
}
Converter represents the ongoing conversion from JSON to XML
func Tokens ¶
func Tokens(j JSONDecoder) *Converter
Tokens provides a JSON converter that implements the xml.TokenReader interface
type JSONDecoder ¶
JSONDecoder represents a type that gives out JSON tokens, usually implemented by *json.Decoder It is encouraged for implementers of this interface to output numbers using the json.Number type, as it reduces needless conversions. Users of the json.Decoder implementation should call the UseNumber method to achieve this
type XMLEncoder ¶
XMLEncoder represents a type that takes XML tokens, usually implemented by *xml.Encoder