1. Home
  2. Docs
  3. golang
  4. 内置库(包-package)
  5. encoding-xml


type Decoder

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder creates a new XML parser reading from r. If r does not implement io.ByteReader, NewDecoder will do its own buffering.


func (*Decoder) Token

func (d *Decoder) Token() (Token, error)

Token returns the next XML token in the input stream. At the end of the input stream, Token returns nil, io.EOF.

Slices of bytes in the returned token data refer to the parser’s internal buffer and remain valid only until the next call to Token. To acquire a copy of the bytes, call CopyToken or the token’s Copy method.

Token expands self-closing elements such as
into separate start and end elements returned by successive calls.

Token guarantees that the StartElement and EndElement tokens it returns are properly nested and matched: if Token encounters an unexpected end element or EOF before all expected end elements, it will return an error.

Token返回输入流中的下一个XML标记。在输入流结束时,Token 返回 nil, io.EOF。


type StartElement

type StartElement struct {
    Name Name
    Attr []Attr

A StartElement represents an XML start element.


type EndElement

type EndElement struct {
    Name Name

An EndElement represents an XML end element.


type CharData

type CharData []byte

A CharData represents XML character data (raw text), in which XML escape sequences have been replaced by the characters they represent.


Was this article helpful to you? Yes No

How can we help?