func FetchRootElement(decoder *xml.Decoder) (startElement xml.StartElement, err error)
FetchRootElement takes in a decoder and returns the first start element within the xml body. This function is useful in fetching the start element of an XML response and ignore the comments and preamble
Array represents the encoding of a XML array type
type Array struct {
// contains filtered or unexported fields
}
func (a *Array) Member() Value
Member adds a new member to the XML array. It returns a Value encoder.
An Attr represents an attribute in an XML element (Name=Value).
type Attr struct { Name Name Value string }
func NewAttribute(local, value string) Attr
NewAttribute returns a pointer to an attribute. It takes in a local name aka attribute name, and value representing the attribute value.
func NewNamespaceAttribute(local, value string) Attr
NewNamespaceAttribute returns a pointer to an attribute. It takes in a local name aka attribute name, and value representing the attribute value.
NewNamespaceAttribute appends `xmlns:` in front of namespace prefix.
For creating a name space attribute representing `xmlns:prefix="http://example.com`, the breakdown would be: local = "prefix" value = "http://example.com"
Encoder is an XML encoder that supports construction of XML values using methods. The encoder takes in a writer and maintains a scratch buffer.
type Encoder struct {
// contains filtered or unexported fields
}
▹ Example
func NewEncoder(w writer) *Encoder
NewEncoder returns an XML encoder
func (e Encoder) Bytes() []byte
Bytes returns the []byte slice of the XML encoder
func (e Encoder) RootElement(element StartElement) Value
RootElement builds a root element encoding It writes it's start element tag. The value should be closed.
func (e Encoder) String() string
String returns the string output of the XML encoder
An EndElement represents an XML end element.
type EndElement struct { Name Name }
ErrorComponents represents the error response fields that will be deserialized from an xml error response body
type ErrorComponents struct { Code string Message string }
func GetErrorResponseComponents(r io.Reader, noErrorWrapping bool) (ErrorComponents, error)
GetErrorResponseComponents returns the error fields from an xml error response body
Map represents the encoding of a XML map type
type Map struct {
// contains filtered or unexported fields
}
func (m *Map) Entry() Value
Entry returns a Value encoder with map's element. It writes the member wrapper start tag for each entry.
A Name represents an XML name (Local) annotated with a name space identifier (Space). In tokens returned by Decoder.Token, the Space identifier is given as a canonical URL, not the short prefix used in the document being parsed.
type Name struct { Space, Local string }
NodeDecoder is a XML decoder wrapper that is responsible to decoding a single XML Node element and it's nested member elements. This wrapper decoder takes in the start element of the top level node being decoded.
type NodeDecoder struct { Decoder *xml.Decoder StartEl xml.StartElement }
func WrapNodeDecoder(decoder *xml.Decoder, startEl xml.StartElement) NodeDecoder
WrapNodeDecoder returns an initialized XMLNodeDecoder
func (d NodeDecoder) GetElement(name string) (t xml.StartElement, err error)
GetElement looks for the given tag name at the current level, and returns the element if found, and skipping over non-matching elements. Returns an error if the node is not found, or if an error occurs while walking the document.
func (d NodeDecoder) Token() (t xml.StartElement, done bool, err error)
Token on a Node Decoder returns a xml StartElement. It returns a boolean that indicates the a token is the node decoder's end node token; and an error which indicates any error that occurred while retrieving the start element
func (d NodeDecoder) Value() (c []byte, err error)
Value provides an abstraction to retrieve char data value within an xml element. The method will return an error if it encounters a nested xml element instead of char data. This method should only be used to retrieve simple type or blob shape values as []byte.
A StartElement represents an XML start element.
type StartElement struct { Name Name Attr []Attr }
func (e StartElement) Copy() StartElement
Copy creates a new copy of StartElement.
func (e StartElement) End() EndElement
End returns the corresponding XML end element.
Value represents an XML Value type XML Value types: Object, Array, Map, String, Number, Boolean.
type Value struct {
// contains filtered or unexported fields
}
func (xv Value) Array() *Array
Array returns an array encoder. By default, the members of array are wrapped with `<member>` element tag. If value is marked as flattened, the start element is used to wrap the members instead of the `<member>` element.
func (xv Value) ArrayWithCustomName(element StartElement) *Array
ArrayWithCustomName returns an array encoder.
It takes named start element as an argument, the named start element will used to wrap xml array entries. for eg, `<someList><customName>entry1</customName></someList>` Here `customName` named start element will be wrapped on each array member.
func (xv Value) Base64EncodeBytes(v []byte)
Base64EncodeBytes writes v as a base64 value in XML string. It will auto close the parent xml element tag.
func (xv Value) BigDecimal(v *big.Float)
BigDecimal encodes v big.Float as XML value. It will auto close the parent xml element tag.
func (xv Value) BigInteger(v *big.Int)
BigInteger encodes v big.Int as XML value. It will auto close the parent xml element tag.
func (xv Value) Boolean(v bool)
Boolean encodes v as a XML boolean. It will auto close the parent xml element tag.
func (xv Value) Byte(v int8)
Byte encodes v as a XML number. It will auto close the parent xml element tag.
func (xv Value) Close()
Close closes the value.
func (xv Value) Double(v float64)
Double encodes v as a XML number. It will auto close the parent xml element tag.
func (xv Value) FlattenedElement(element StartElement) Value
FlattenedElement returns flattened element encoding. It returns a Value. This method should be used for flattened shapes.
Unlike MemberElement, flattened element will NOT write element tags directly for the associated start element.
The value returned by the FlattenedElement does not need to be closed.
func (xv Value) Float(v float32)
Float encodes v as a XML number. It will auto close the parent xml element tag.
func (xv Value) Integer(v int32)
Integer encodes v as a XML number. It will auto close the parent xml element tag.
func (xv Value) IsFlattened() bool
IsFlattened returns true if value is for flattened shape.
func (xv Value) Long(v int64)
Long encodes v as a XML number. It will auto close the parent xml element tag.
func (xv Value) Map() *Map
Map returns a map encoder. By default, the map entries are wrapped with `<entry>` element tag.
If value is marked as flattened, the start element is used to wrap the entry instead of the `<member>` element.
func (xv Value) MemberElement(element StartElement) Value
MemberElement does member element encoding. It returns a Value. Member Element method should be used for all shapes except flattened shapes.
A call to MemberElement will write nested element tags directly using the provided start element. The value returned by MemberElement should be closed.
func (xv Value) Short(v int16)
Short encodes v as a XML number. It will auto close the parent xml element tag.
func (xv Value) String(v string)
String encodes v as a XML string. It will auto close the parent xml element tag.
func (xv Value) Write(v []byte, escapeXMLText bool)
Write writes v directly to the xml document if escapeXMLText is set to true, write will escape text. It will auto close the parent xml element tag.