Documentation
¶
Overview ¶
Package jvxml implements an alternative encoder for XML data.
There are two differences between this package and the corresponding code in the standard library's encoding/xml package. First, this package implements an additional EmptyElement type to represent empty XML elements. Second, this package exports the IsName function.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type EmptyElement ¶
An EmptyElement represents an empty XML element.
func (EmptyElement) Copy ¶
func (e EmptyElement) Copy() EmptyElement
Copy creates a new copy of StartElement.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
An Encoder writes XML data to an output stream.
func NewEncoder ¶
NewEncoder returns a new encoder that writes to w.
func (*Encoder) Close ¶
Close the Encoder, indicating that no more data will be written. It flushes any buffered XML to the underlying writer and returns an error if the written XML is invalid (e.g. by containing unclosed elements).
func (*Encoder) EncodeToken ¶
EncodeToken writes the given XML token to the stream. It returns an error if [StartElement] and [EndElement] tokens are not properly matched.
EncodeToken does not call Encoder.Flush, because usually it is part of a larger operation such as [Encoder.Encode] or [Encoder.EncodeElement] (or a custom [Marshaler]'s MarshalXML invoked during those), and those will call Flush when finished. Callers that create an Encoder and then invoke EncodeToken directly, without using Encode or EncodeElement, need to call Flush when finished to ensure that the XML is written to the underlying writer.
EncodeToken allows writing a [ProcInst] with Target set to "xml" only as the first token in the stream.
func (*Encoder) Flush ¶
Flush flushes any buffered XML to the underlying writer. See the Encoder.EncodeToken documentation for details about when it is necessary.
type Token ¶
type Token any
A Token is an interface holding one of the token types: xml.StartElement, xml.EndElement, EmptyElement, xml.CharData, xml.Comment, xml.ProcInst, or xml.Directive.