Documentation
¶
Index ¶
Constants ¶
const ( TokenTypeInvalid = iota TokenTypeStartElement TokenTypeEndElement TokenTypeProcInst TokenTypeDirective TokenTypeTextElement TokenTypeCharData )
constants for Token.Kind
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attr ¶
Attr is an attribute of an element. Only tokens of type TokenTypeStartElement can have attributes.
type Decoder ¶
type Decoder interface { // NextToken decodes and stores the next Token into // the provided Token pointer. // Only the fields relevant for the decoded token type // are written to the Token. Other fields may have previous // values. The caller should thus determine the Token.Kind // and then only read/touch the fields relevant for that kind. NextToken(t *Token) error // Reset resets the Decoder to the given io.Reader. Reset(r io.Reader) }
Decoder decodes an XML input stream into Token values.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder encodes Token values to an io.Writer.
func NewEncoder ¶
func NewEncoder(w io.Writer, middlewares ...EncoderMiddleware) *Encoder
NewEncoder creates a new Encoder with the given middlewares and returns a pointer to it.
func (*Encoder) EncodeToken ¶
EncodeToken first calls any EncoderMiddleware and then writes the byte-representation of that Token to the io.Writer of this Encoder.
type EncoderMiddleware ¶
type EncoderMiddleware interface { // EncodeToken will be called by the Encoder before the provided Token // is finally byte-encoded into the io.Writer. // The Encoder will ensure that the pointed-to Token and all its contained // field values will remain unmodified for the lexical scope of the // XML-element represented by the Token. // If, for example, the Token represents a TokenTypeStartElement, then // the Token and all of its contained fields/byte-slices will contain // their values until after its corresponding TokenTypeEndElement is processed // by the EncoderMiddleware. EncodeToken(token *Token) error // Reset resets the state of an EncoderMiddleware. // This can be used to e.g. reset all pre-allocated data structures // and reinitialize the EncoderMiddleware to the state before the // any first call to EncodeToken. Reset() }
EncoderMiddleware allows to pre-process a Token before it is finally encoded/written.
type Name ¶
Name is a name with a possible prefix like "xmlns:blubb" or simply without prefix like "a"
type NamespaceModifier ¶
type NamespaceModifier struct { PreserveOriginalPrefixes bool // contains filtered or unexported fields }
NamespaceModifier can be used to obtain information about the effective namespace of a decoded Token via NamespaceOfToken and to canonicalize/minify namespace declarations.
func NewNamespaceModifier ¶
func NewNamespaceModifier() *NamespaceModifier
NewNamespaceModifier creates a new NamespaceModifier and returns a pointer to it.
func (*NamespaceModifier) EncodeToken ¶
func (thiz *NamespaceModifier) EncodeToken(t *Token) error
EncodeToken will be called by the Encoder before the provided Token is finally byte-encoded into the io.Writer. The Encoder will ensure that the pointed-to Token and all its contained field values will remain unmodified for the lexical scope of the XML-element represented by the Token. If, for example, the Token represents a TokenTypeStartElement, then the Token and all of its contained fields/byte-slices will contain their values until after its corresponding TokenTypeEndElement is processed by the EncoderMiddleware.
func (*NamespaceModifier) NamespaceOfToken ¶
func (thiz *NamespaceModifier) NamespaceOfToken(t *Token) []byte
NamespaceOfToken returns the effective namespace (as byte slice) of the pointed-to Token. The caller must make sure that the Token's fields/values will remain unmodified for the lexical scope of the XML element represented by that token, as per the documentation of EncoderMiddleware.EncodeToken.
func (*NamespaceModifier) Reset ¶
func (thiz *NamespaceModifier) Reset()
Reset resets this NamespaceModifier.
type Token ¶
type Token struct { // only for TokenTypeStartElement, TokenTypeEndElement and TokenTypeProcInst Name Name // only for TokenTypeStartElement Attr []Attr // only for TokenTypeDirective, TokenTypeTextElement, TokenTypeCharData and TokenTypeProcInst ByteData []byte Kind byte }
Token represents the union of all possible token types with their respective information.