xg

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2022 License: MIT Imports: 8 Imported by: 1

README

xmlgo

Go XML library

A very simple XML parser and writer that features functional API instead of object/reflect-based approach implemented in standard GO library.

Documentation

Index

Constants

View Source
const (
	ErrCodeOk = ErrCode(iota)
	ErrCustom
	ErrCodeUnexpectedEOF
	ErrCodeUnexpectedContent
	ErrCodeUnterminatedQStr
	ErrCodeUnterminatedCDATA
	ErrCodeUnsupportedFeature
	ErrCodeExpectedAttrName
	ErrCodeExpectedEQ
	ErrCodeExpectedQStr
	ErrCodeExpectedOTag
	ErrCodeInvalidSchema
	ErrCodeInvalidXmlDecl
	ErrMismatchingTag
	ErrCodeMissingRoot
	ErrUnterminatedComment
	ErrInvalidComment
	ErrUnterminatedPI
)
View Source
const (
	EOF           // end of file (buffer)
	Err           // error
	XmlDecl       // <?xml version="1.0" encoding="UTF-8"?>
	DocTypeDecl   // <!DOCTYPE ... >
	Tag           // <identifier
	CloseEmptyTag // />
	BeginContent  // >
	EndContent    // </identifier>
	Attrib        // identifier="qstring" or identifier='qstring'
	SData         // content string data
	CData         // cdata tag content
	Comment       // <!-- comment -->
	PI            // <?name value?>
)

Variables

View Source
var ErrNoMoreContent = errors.New("no more content available")

Functions

func CalcLocation

func CalcLocation(buf string, byteoffset int) (line, pos int)

func NewError

func NewError(ec ErrCode, buf string, offset int) error

func ParseTokens

func ParseTokens(buf string, ontoken func(t *Token) error) error

Types

type AttributeList

type AttributeList []*Token

func (AttributeList) Attr

func (aa AttributeList) Attr(name string) (string, bool)

type Content

type Content struct {
	// contains filtered or unexported fields
}

func Open

func Open(buf string) *Content

func (*Content) ChildStringContent

func (ci *Content) ChildStringContent() RawString

ChildStringContent extracts subnode string content

If subnode is empty, or its content is not a simple string, this function returns empty string.

This is useful for parsing <tag>string-content</tag> nodes

func (*Content) Err

func (ci *Content) Err() error

func (*Content) HandleTag

func (ci *Content) HandleTag(callback func(attrs AttributeList, content *Content) error)

func (*Content) IsCData

func (ci *Content) IsCData() bool

func (*Content) IsComment

func (ci *Content) IsComment() bool

func (*Content) IsPI

func (ci *Content) IsPI() bool

func (*Content) IsSData

func (ci *Content) IsSData() bool

func (*Content) IsTag

func (ci *Content) IsTag() bool

func (*Content) IsXmlDecl

func (ci *Content) IsXmlDecl() bool

func (*Content) Kind

func (ci *Content) Kind() TokenKind

func (*Content) MakeError

func (ci *Content) MakeError(prefix, msg string) error

func (*Content) Name

func (ci *Content) Name() NameString

func (*Content) Next

func (ci *Content) Next() (ok bool)

func (*Content) NextTag

func (ci *Content) NextTag() bool

func (*Content) Raw

func (ci *Content) Raw() (whitePrefix, tokenStr string)

func (*Content) Value

func (ci *Content) Value() RawString

type ContentHandler

type ContentHandler = func(t *Token) error

type ErrCode

type ErrCode int

func (ErrCode) Failed

func (ec ErrCode) Failed() bool

func (ErrCode) String

func (ec ErrCode) String() string

func (ErrCode) Succeeded

func (ec ErrCode) Succeeded() bool

type Marshaler

type Marshaler interface {
	MarshalXG(w *Writer) error
}

type NameString

type NameString string

type RawString

type RawString string

func (RawString) Unscrambled

func (rs RawString) Unscrambled() string

type TagHandler

type TagHandler func(tag *Token, attrs AttributeList, content *Content) error

type Token

type Token struct {
	Kind        TokenKind
	Error       error
	Name        NameString
	Value       RawString
	WhitePrefix string
	Raw         string
	SrcPos      int
}

func (*Token) IsDone

func (t *Token) IsDone() bool

func (*Token) IsError

func (t *Token) IsError() bool

type TokenKind

type TokenKind int

func (TokenKind) String

func (t TokenKind) String() string

type UnsupportedTypeError

type UnsupportedTypeError struct {
	Type reflect.Type
}

UnsupportedTypeError is returned when Marshal encounters a type that cannot be converted into XML.

func (*UnsupportedTypeError) Error

func (e *UnsupportedTypeError) Error() string

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter(out io.Writer) *Writer

func (*Writer) Attr

func (w *Writer) Attr(name string, value interface{})

func (*Writer) BOM

func (w *Writer) BOM()

func (*Writer) BeginContent

func (w *Writer) BeginContent()

func (*Writer) CTag

func (w *Writer) CTag()

func (*Writer) Comment

func (w *Writer) Comment(s string)

func (*Writer) OTag

func (w *Writer) OTag(name string)

func (*Writer) OptAttr

func (w *Writer) OptAttr(name string, value interface{})

func (*Writer) OptStringAttr

func (w *Writer) OptStringAttr(name string, value string)

func (*Writer) String

func (w *Writer) String(s string)

func (*Writer) StringAttr

func (w *Writer) StringAttr(name string, value string)

func (*Writer) Write

func (w *Writer) Write(v interface{})

func (*Writer) XmlDecl

func (w *Writer) XmlDecl()

Jump to

Keyboard shortcuts

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