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

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.

如果r没有实现io.ByteReader,NewDecoder将自己做缓冲。

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。

返回的令牌数据中的字节片指的是解析器的内部缓冲区,并且只在下次调用Token之前保持有效。要获得字节的拷贝,可以调用CopyToken或令牌的Copy方法。

type StartElement

type StartElement struct {
    Name Name
    Attr []Attr
}

A StartElement represents an XML start element.

一个StartElement代表一个XML的开始元素。

type EndElement

type EndElement struct {
    Name Name
}

An EndElement represents an XML end element.

一个EndElement代表一个XML结束元素。

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.

CharData代表XML字符数据(原始文本),其中XML转义序列已被它们所代表的字符取代。

Was this article helpful to you? Yes No

How can we help?