xmlenc

package
v7.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package xmlenc 有关文档格式编解码处理

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(p *Parser, v interface{}, namespace string)

Decode 将 p 中的 XML 内容解码至 v 对象中

namespace 如果不为空表示当前的 xml 所在的命名空间,只有该命名空间的元素才会被正确识别。

func Encode

func Encode(indent string, v interface{}, namespace, prefix string) ([]byte, error)

Encode 将 v 转换成 XML 内容

namespace 指定 XML 的命名空间; prefix 命名空间的前缀,如果为空表示使用默认命名空间;

Types

type AttrDecoder

type AttrDecoder interface {
	// DecodeXMLAttr 解析属性值
	//
	// 接口应该只返回 *core.Error 作为错误对象。
	DecodeXMLAttr(p *Parser, attr *Attribute) error
}

AttrDecoder 实现从 attr 中解码内容到当前对象的值

type AttrEncoder

type AttrEncoder interface {
	// EncodeXMLAttr 仅需要返回属性的 XML 表示,不需要包含属性值的引号字符。
	EncodeXMLAttr() (string, error)
}

AttrEncoder 将属性值编码成符合 XML 规范的值

type Attribute

type Attribute struct {
	core.Location
	Name  Name
	Value String
}

Attribute 表示 XML 属性

type Base

type Base struct {
	core.Location
	UsageKey message.Reference `apidoc:"-"` // 表示对当前元素的一个说明内容的翻译 ID
}

Base 所有文档节点的基本元素

func (Base) Usage

func (b Base) Usage() string

Usage 本地化的当前字段介绍内容

type BaseAttribute

type BaseAttribute struct {
	Base
	AttributeName Name `apidoc:"-"`
}

BaseAttribute 所有 XML 属性节点的基本元素

type BaseTag

type BaseTag struct {
	Base
	StartTag Name `apidoc:"-"` // 表示起始标签名
	EndTag   Name `apidoc:"-"` // 表示标签的结束名称,如果是自闭合的标签,此值的 Local.Value 为空。
}

BaseTag 所有 XML 标签的基本元素

func (*BaseTag) SelfClose

func (b *BaseTag) SelfClose() bool

SelfClose 当前是否为自闭合标签

type CData

type CData struct {
	BaseTag
	Value String
}

CData 表示 XML 的 CDATA 数据

type Comment

type Comment struct {
	core.Location
	Value String
}

Comment 表示 XML 的注释

type Decoder

type Decoder interface {
	// DecodeXML 从 p 中读取内容并实例化到当前对象中
	//
	// 必须要同时从 p 中读取相应的 EndElement 才能返回。
	// end 表示 EndElement.End 的值。
	//
	// NOTE: 如果是自闭合标签,则不会调用该接口。
	//
	// 接口应该只返回 *core.Error 作为错误对象。
	DecodeXML(p *Parser, start *StartElement) (end *EndElement, err error)
}

Decoder 实现从 p 中解码内容到当前对象的值

type Encoder

type Encoder interface {
	// EncodeXML 仅需要返回元素内容的 XML 编码,不需要包含本身的标签和属性。
	EncodeXML() (string, error)
}

Encoder 将元素内容编码成 XML 内容

type EndElement

type EndElement struct {
	core.Location
	Name Name
}

EndElement XML 的结束元素

type Instruction

type Instruction struct {
	core.Location
	Name       String
	Attributes []*Attribute
}

Instruction 表示 XML 的指令

type Name

type Name struct {
	core.Location
	Prefix String
	Local  String
}

Name 表示 XML 中的名称

func (Name) Equal

func (n Name) Equal(v Name) bool

Equal 两个 name 是否相等

func (Name) String

func (n Name) String() string

String fmt.Stringer

type Parser

type Parser struct {
	*lexer.Lexer
	*core.MessageHandler
}

Parser 代码块的解析器

func NewParser

func NewParser(h *core.MessageHandler, b core.Block) (*Parser, error)

NewParser 声明新的 Parser 实例

func (*Parser) Token

func (p *Parser) Token() (token interface{}, loc core.Location, err error)

Token 返回下一个 token 对象

token 可能的类型为 *StartElement、*EndElement、*Instruction、*Attribute、*CData、*Comment 和 *String。 其中 *String 用于表示 XML 元素的内容。

loc 表示返回的 token 所占的范围; 当返回 nil, {}, io.EOF 时,表示已经结束

type Sanitizer

type Sanitizer interface {
	// Sanitize 验证数据是否正确
	//
	// 可以通过 p.Error 等方法输出错误信息
	Sanitize(p *Parser)
}

Sanitizer 用于验证和修改对象中的数据

type StartElement

type StartElement struct {
	core.Location
	Name       Name
	Attributes []*Attribute
	SelfClose  bool // 是否自闭合
}

StartElement 表示 XML 的元素

func (*StartElement) Match

func (s *StartElement) Match(end *EndElement) bool

Match 是否与 end 相匹配

type String

type String struct {
	core.Location
	Value string
}

String 表示 XML 的字符串数据

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL