helium

package module
v0.0.0-...-8e504ee Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2019 License: MIT Imports: 15 Imported by: 0

README

helium

Build Status GoDoc

What on earth?

This is an exercise in rewriting libxml2 in its entirety in Go. Why? I've run into performance blockers while using cgo and libxml2, and I couldn't squeeze out that last drop of performance out of it. Also, there was also this, which I thought was a shame to not be able to handle XML using pure Go.

So I started -- and I still have a long way to go.

SYNOPSIS

Parsing XML into a DOM model, then dumping it:

import "github.com/lestrrat-go/helium"

func main() {
    doc, err := helium.Parse(`.... xml string ....`)
    if err != nil {
        panic("failed to parse XML: " + err.Error())
    }

    // Dump this XML
    doc.XML(os.Stdout)
}

Using command line helium-lint (very under developed right now):

helium-lint xmlfile ...
cat xmlfile | helium-lint

Get it

go get github.com/lestrrat-go/helium

Test it

go test

In order to get helpful debug messages:

go test -tags debug

Current status

  • Good news: parse/dump basic XML with some DTDs are now working.
  • Bad news: I have run out of tuits. I intend to work on this from time to time, but I REALLY need people's help. See "Contributing" below.
  • While XML declaration is parsed, encoding is ignored, and assumed to be UTF-8

Contributing

I won't have much time to discuss: let the code talk: Give me PRs that are self-explanatory! :)

The goal for the moment is to "port" libxml2. That means that where possible, we should just steal their code, even if things aren't too go-ish. We'll polish after we have a compatible implementation. So don't debate for optimal go-ness unless it's a really low hanging fruit.

Help in forms for PRs is better, but if you insiste, Amazon gift cards to lestrrat at gmail is appreciated ;)

To get started, see notes on test structure below. Grab some files from libxml2, and see if things work. If it doesn't work, fix it! :)

Test structure

As of this writing, dump_test.go and sax_test.go both look for the presence of XML files under test directory, and parse+dumps appropriate output after seeing that there's a corresponding *.dump or *.sax2 files.

For SAX tests, do note that letter casing and such are different from that of libxml2.

What's with the naming?

I thought it sounded cool. Not set in stone, so we may change it later.

Documentation

Index

Constants

View Source
const (
	XMLNamespace = "http://www.w3.org/XML/1998/namespace"
	XMLNsPrefix  = "xmlns"
	XMLPrefix    = "xml"
	XMLTextNoEnc = "textnoenc"
)
View Source
const (
	StandaloneInvalidValue = -99
	StandaloneExplicitYes  = 1
	StandaloneExplicitNo   = 0
	StandaloneNoXMLDecl    = -1
	StandaloneImplicitNo   = -2
)
View Source
const MaxNameLength = 50000
View Source
const Version = `0.0.1`

Variables

View Source
var (
	ErrNilNode            = errors.New("nil node")
	ErrInvalidOperation   = errors.New("operation cannot be performed")
	ErrDuplicateAttribute = errors.New("duplicate attribute")
)
View Source
var (
	EntityLT         = newEntity("lt", InternalPredefinedEntity, "", "", "<", "&lt;")
	EntityGT         = newEntity("gt", InternalPredefinedEntity, "", "", ">", "&gt;")
	EntityAmpersand  = newEntity("amp", InternalPredefinedEntity, "", "", "&", "&amp;")
	EntityApostrophe = newEntity("apos", InternalPredefinedEntity, "", "", "'", "&apos;")
	EntityQuote      = newEntity("quot", InternalPredefinedEntity, "", "", `"`, "&quot;")
)
View Source
var (
	ErrAmpersandRequired            = errors.New("'&' was required here")
	ErrAttrListNotFinished          = errors.New("attrlist must finish with a ')'")
	ErrAttrListNotStarted           = errors.New("attrlist must start with a '('")
	ErrAttributeNameRequired        = errors.New("attribute namewas required here (ATTLIST)")
	ErrByteCursorRequired           = errors.New("inconsistent state: required ByteCursor")
	ErrDocTypeNameRequired          = errors.New("doctype name required")
	ErrDocTypeNotFinished           = errors.New("doctype not finished")
	ErrDocumentEnd                  = errors.New("extra content at document end")
	ErrEOF                          = errors.New("end of file reached")
	ErrElementContentNotFinished    = errors.New("element content not finished")
	ErrEmptyDocument                = errors.New("start tag expected, '<' not found")
	ErrEntityNotFound               = errors.New("entity not found")
	ErrEqualSignRequired            = errors.New("'=' was required here")
	ErrGtRequired                   = errors.New("'>' was required here")
	ErrHyphenInComment              = errors.New("'--' not allowed in comment")
	ErrInvalidChar                  = errors.New("invalid char")
	ErrInvalidComment               = errors.New("invalid comment section")
	ErrInvalidCDSect                = errors.New("invalid CDATA section")
	ErrInvalidDocument              = errors.New("invalid document")
	ErrInvalidDTD                   = errors.New("invalid DTD section")
	ErrInvalidElementDecl           = errors.New("invalid element declaration")
	ErrInvalidEncodingName          = errors.New("invalid encoding name")
	ErrInvalidName                  = errors.New("invalid xml name")
	ErrInvalidProcessingInstruction = errors.New("invalid processing instruction")
	ErrInvalidVersionNum            = errors.New("invalid version")
	ErrInvalidXMLDecl               = errors.New("invalid XML declration")
	ErrInvalidParserCtx             = errors.New("invalid parser context")
	ErrLtSlashRequired              = errors.New("'</' is required")
	ErrMisplacedCDATAEnd            = errors.New("misplaced CDATA end ']]>'")
	ErrNameTooLong                  = errors.New("name is too long")
	ErrNameRequired                 = errors.New("name is required")
	ErrNmtokenRequired              = errors.New("nmtoken is required")
	ErrNotationNameRequired         = errors.New("notation name expected in NOTATION declaration")
	ErrNotationNotFinished          = errors.New("notation must finish with a ')'")
	ErrNotationNotStarted           = errors.New("notation must start with a '('")
	ErrOpenParenRequired            = errors.New("'(' is required")
	ErrPCDATARequired               = errors.New("'#PCDATA' required")
	ErrPercentRequired              = errors.New("'%' is required")
	ErrPrematureEOF                 = errors.New("end of document reached")
	ErrUndeclaredEntity             = errors.New("undeclared entity")
	ErrSemicolonRequired            = errors.New("';' is required")
	ErrSpaceRequired                = errors.New("space required")
	ErrStartTagRequired             = errors.New("start tag expected, '<' not found")
	ErrValueRequired                = errors.New("value required")
)
View Source
var (
	ErrCDATANotFinished = errors.New("invalid CDATA section (premature end)")
	ErrCDATAInvalid     = errors.New("invalid CDATA section")
)
View Source
var ErrParseSucceeded = errors.New("parse succeeded")

Functions

func Walk

func Walk(n Node, f WalkFunc) error

Types

type Attribute

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

func (*Attribute) AddChild

func (n *Attribute) AddChild(cur Node) error

func (*Attribute) AddContent

func (n *Attribute) AddContent(b []byte) error

func (*Attribute) AddSibling

func (n *Attribute) AddSibling(cur Node) error

func (Attribute) Content

func (n Attribute) Content() []byte

func (Attribute) FirstChild

func (n Attribute) FirstChild() Node

func (*Attribute) IsDefault

func (n *Attribute) IsDefault() bool

func (Attribute) LastChild

func (n Attribute) LastChild() Node

func (Attribute) LocalName

func (n Attribute) LocalName() string

func (Attribute) Name

func (n Attribute) Name() string

func (*Attribute) NextAttribute

func (n *Attribute) NextAttribute() *Attribute

NextAttribute is a thin wrapper around NextSibling() so that the caller does not have to constantly type assert

func (Attribute) NextSibling

func (n Attribute) NextSibling() Node

func (Attribute) OwnerDocument

func (n Attribute) OwnerDocument() *Document

func (Attribute) Parent

func (n Attribute) Parent() Node

func (Attribute) Prefix

func (n Attribute) Prefix() string

func (Attribute) PrevSibling

func (n Attribute) PrevSibling() Node

func (*Attribute) Replace

func (n *Attribute) Replace(cur Node)

func (*Attribute) SetDefault

func (n *Attribute) SetDefault(b bool)

func (*Attribute) SetNextSibling

func (n *Attribute) SetNextSibling(cur Node)

func (*Attribute) SetOwnerDocument

func (n *Attribute) SetOwnerDocument(doc *Document)

func (*Attribute) SetParent

func (n *Attribute) SetParent(cur Node)

func (*Attribute) SetPrevSibling

func (n *Attribute) SetPrevSibling(cur Node)

func (*Attribute) SetTreeDoc

func (n *Attribute) SetTreeDoc(doc *Document)

func (Attribute) Type

func (n Attribute) Type() ElementType

func (Attribute) URI

func (n Attribute) URI() string

func (Attribute) Value

func (n Attribute) Value() string

type AttributeDecl

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

AttributeDecl is an xml attribute delcaration from DTD

func (*AttributeDecl) AddChild

func (n *AttributeDecl) AddChild(cur Node) error

func (*AttributeDecl) AddContent

func (n *AttributeDecl) AddContent(b []byte) error

func (*AttributeDecl) AddSibling

func (n *AttributeDecl) AddSibling(cur Node) error

func (AttributeDecl) Content

func (n AttributeDecl) Content() []byte

func (AttributeDecl) FirstChild

func (n AttributeDecl) FirstChild() Node

func (AttributeDecl) LastChild

func (n AttributeDecl) LastChild() Node

func (AttributeDecl) LocalName

func (n AttributeDecl) LocalName() string

func (AttributeDecl) Name

func (n AttributeDecl) Name() string

func (AttributeDecl) NextSibling

func (n AttributeDecl) NextSibling() Node

func (AttributeDecl) OwnerDocument

func (n AttributeDecl) OwnerDocument() *Document

func (AttributeDecl) Parent

func (n AttributeDecl) Parent() Node

func (AttributeDecl) PrevSibling

func (n AttributeDecl) PrevSibling() Node

func (*AttributeDecl) Replace

func (n *AttributeDecl) Replace(cur Node)

func (*AttributeDecl) SetNextSibling

func (n *AttributeDecl) SetNextSibling(cur Node)

func (*AttributeDecl) SetOwnerDocument

func (n *AttributeDecl) SetOwnerDocument(doc *Document)

func (*AttributeDecl) SetParent

func (n *AttributeDecl) SetParent(cur Node)

func (*AttributeDecl) SetPrevSibling

func (n *AttributeDecl) SetPrevSibling(cur Node)

func (*AttributeDecl) SetTreeDoc

func (n *AttributeDecl) SetTreeDoc(doc *Document)

func (AttributeDecl) Type

func (n AttributeDecl) Type() ElementType

type AttributeDefault

type AttributeDefault int
const (
	AttrDefaultInvalid AttributeDefault = iota
	AttrDefaultNone
	AttrDefaultRequired
	AttrDefaultImplied
	AttrDefaultFixed
)

type AttributeType

type AttributeType int
const (
	AttrInvalid AttributeType = iota
	AttrCDATA
	AttrID
	AttrIDRef
	AttrIDRefs
	AttrEntity
	AttrEntities
	AttrNmtoken
	AttrNmtokens
	AttrEnumeration
	AttrNotation
)

type Comment

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

Comment is just a wrapper around Node so that we can use Go-ish type checks

func (*Comment) AddChild

func (n *Comment) AddChild(cur Node) error

func (*Comment) AddContent

func (n *Comment) AddContent(b []byte) error

func (*Comment) AddSibling

func (n *Comment) AddSibling(cur Node) error

AddSibling adds a new sibling to the end of the sibling nodes.

func (Comment) Content

func (n Comment) Content() []byte

func (Comment) Name

func (n Comment) Name() string

func (Comment) Namespace

func (n Comment) Namespace() *Namespace

func (Comment) Namespaces

func (n Comment) Namespaces() []*Namespace

func (Comment) Prefix

func (n Comment) Prefix() string

func (*Comment) Replace

func (n *Comment) Replace(cur Node)

func (*Comment) SetNamespace

func (n *Comment) SetNamespace(prefix, uri string, activate ...bool) error

func (*Comment) SetTreeDoc

func (n *Comment) SetTreeDoc(doc *Document)

func (Comment) URI

func (n Comment) URI() string

type DTD

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

func (*DTD) AddChild

func (dtd *DTD) AddChild(cur Node) error

func (*DTD) AddContent

func (dtd *DTD) AddContent(b []byte) error

func (*DTD) AddElementDecl

func (dtd *DTD) AddElementDecl(name string, typ ElementTypeVal, content *ElementContent) (*ElementDecl, error)

func (*DTD) AddEntity

func (dtd *DTD) AddEntity(name string, typ EntityType, publicID, systemID, content string) (*Entity, error)

func (*DTD) AddSibling

func (dtd *DTD) AddSibling(cur Node) error

func (DTD) Content

func (n DTD) Content() []byte

func (DTD) FirstChild

func (n DTD) FirstChild() Node

func (*DTD) Free

func (dtd *DTD) Free()

func (*DTD) GetElementDesc

func (dtd *DTD) GetElementDesc(name string) (*ElementDecl, bool)

func (DTD) LastChild

func (n DTD) LastChild() Node

func (DTD) LocalName

func (n DTD) LocalName() string

func (*DTD) LookupAttribute

func (dtd *DTD) LookupAttribute(name, prefix, elem string) (*AttributeDecl, bool)

func (*DTD) LookupElement

func (dtd *DTD) LookupElement(name, prefix string) (*ElementDecl, bool)

func (*DTD) LookupEntity

func (dtd *DTD) LookupEntity(name string) (*Entity, bool)

func (*DTD) LookupParameterEntity

func (dtd *DTD) LookupParameterEntity(name string) (*Entity, bool)

func (DTD) Name

func (n DTD) Name() string

func (DTD) NextSibling

func (n DTD) NextSibling() Node

func (DTD) OwnerDocument

func (n DTD) OwnerDocument() *Document

func (DTD) Parent

func (n DTD) Parent() Node

func (DTD) PrevSibling

func (n DTD) PrevSibling() Node

func (*DTD) RegisterAttribute

func (dtd *DTD) RegisterAttribute(attr *AttributeDecl) error

func (*DTD) RemoveElement

func (dtd *DTD) RemoveElement(name, prefix string)

func (*DTD) Replace

func (dtd *DTD) Replace(cur Node)

func (*DTD) SetNextSibling

func (n *DTD) SetNextSibling(cur Node)

func (*DTD) SetOwnerDocument

func (n *DTD) SetOwnerDocument(doc *Document)

func (*DTD) SetParent

func (n *DTD) SetParent(cur Node)

func (*DTD) SetPrevSibling

func (n *DTD) SetPrevSibling(cur Node)

func (*DTD) SetTreeDoc

func (dtd *DTD) SetTreeDoc(doc *Document)

func (DTD) Type

func (n DTD) Type() ElementType

type Document

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

func CreateDocument

func CreateDocument() *Document

func NewDocument

func NewDocument(version, encoding string, standalone DocumentStandaloneType) *Document

func Parse

func Parse(b []byte) (*Document, error)

func (*Document) AddChild

func (d *Document) AddChild(cur Node) error

func (*Document) AddContent

func (d *Document) AddContent(b []byte) error

func (*Document) AddEntity

func (d *Document) AddEntity(name string, typ EntityType, externalID, systemID, content string) (*Entity, error)

func (*Document) AddSibling

func (d *Document) AddSibling(n Node) error

func (Document) Content

func (n Document) Content() []byte

func (*Document) CreateAttribute

func (d *Document) CreateAttribute(name, value string, ns *Namespace) (attr *Attribute, err error)

func (*Document) CreateCharRef

func (d *Document) CreateCharRef(name string) (*EntityRef, error)

func (*Document) CreateComment

func (d *Document) CreateComment(value []byte) (*Comment, error)

func (*Document) CreateDTD

func (d *Document) CreateDTD() (*DTD, error)

func (*Document) CreateElement

func (d *Document) CreateElement(name string) (*Element, error)

func (*Document) CreateElementContent

func (d *Document) CreateElementContent(name string, etype ElementContentType) (*ElementContent, error)

func (*Document) CreateInternalSubset

func (d *Document) CreateInternalSubset(name, externalID, systemID string) (*DTD, error)

func (*Document) CreateNamespace

func (d *Document) CreateNamespace(prefix, uri string) (*Namespace, error)

func (*Document) CreatePI

func (d *Document) CreatePI(target, data string) (*ProcessingInstruction, error)

func (*Document) CreateReference

func (d *Document) CreateReference(name string) (*EntityRef, error)

func (*Document) CreateText

func (d *Document) CreateText(value []byte) (*Text, error)

func (*Document) Encoding

func (d *Document) Encoding() string

func (*Document) ExtSubset

func (d *Document) ExtSubset() *DTD

func (Document) FirstChild

func (n Document) FirstChild() Node

func (*Document) GetEntity

func (d *Document) GetEntity(name string) (ent *Entity, found bool)

func (*Document) GetParameterEntity

func (d *Document) GetParameterEntity(name string) (*Entity, bool)

func (*Document) IntSubset

func (d *Document) IntSubset() *DTD

func (*Document) InternalSubset

func (d *Document) InternalSubset() (*DTD, error)

func (*Document) IsMixedElement

func (d *Document) IsMixedElement(name string) (bool, error)

func (Document) LastChild

func (n Document) LastChild() Node

func (Document) LocalName

func (n Document) LocalName() string

func (Document) Name

func (n Document) Name() string

func (Document) NextSibling

func (n Document) NextSibling() Node

func (Document) OwnerDocument

func (n Document) OwnerDocument() *Document

func (Document) Parent

func (n Document) Parent() Node

func (Document) PrevSibling

func (n Document) PrevSibling() Node

func (*Document) Replace

func (d *Document) Replace(n Node)

func (*Document) SetDocumentElement

func (d *Document) SetDocumentElement(root Node) error

func (*Document) SetNextSibling

func (n *Document) SetNextSibling(cur Node)

func (*Document) SetOwnerDocument

func (n *Document) SetOwnerDocument(doc *Document)

func (*Document) SetParent

func (n *Document) SetParent(cur Node)

func (*Document) SetPrevSibling

func (n *Document) SetPrevSibling(cur Node)

func (*Document) SetTreeDoc

func (d *Document) SetTreeDoc(doc *Document)

func (*Document) Standalone

func (d *Document) Standalone() DocumentStandaloneType

func (Document) Type

func (n Document) Type() ElementType

func (*Document) Version

func (d *Document) Version() string

func (*Document) XML

func (d *Document) XML(out io.Writer) error

func (Document) XMLString

func (d Document) XMLString() (string, error)

type DocumentStandaloneType

type DocumentStandaloneType int

type Dumper

type Dumper struct{}

func (*Dumper) DumpDoc

func (d *Dumper) DumpDoc(out io.Writer, doc *Document) error

func (*Dumper) DumpNode

func (d *Dumper) DumpNode(out io.Writer, n Node) error

type Element

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

Element is just a wrapper around Node so that we can use Go-ish type checks

func (*Element) AddChild

func (n *Element) AddChild(cur Node) error

AddChild adds a new child node to the end of the children nodes.

func (*Element) AddContent

func (n *Element) AddContent(b []byte) error

func (*Element) AddSibling

func (n *Element) AddSibling(cur Node) error

AddSibling adds a new sibling to the end of the sibling nodes.

func (Element) Attributes

func (n Element) Attributes() []*Attribute

func (Element) Name

func (n Element) Name() string

func (Element) Namespace

func (n Element) Namespace() *Namespace

func (Element) Namespaces

func (n Element) Namespaces() []*Namespace

func (Element) Prefix

func (n Element) Prefix() string

func (*Element) Replace

func (n *Element) Replace(cur Node)

func (*Element) SetAttribute

func (n *Element) SetAttribute(name, value string) error

func (*Element) SetNamespace

func (n *Element) SetNamespace(prefix, uri string, activate ...bool) error

func (*Element) SetTreeDoc

func (n *Element) SetTreeDoc(doc *Document)

func (Element) URI

func (n Element) URI() string

func (*Element) XML

func (n *Element) XML(out io.Writer) error

func (Element) XMLString

func (n Element) XMLString() (string, error)

type ElementContent

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

type ElementContentOccur

type ElementContentOccur int
const (
	ElementContentOnce ElementContentOccur = iota + 1
	ElementContentOpt
	ElementContentMult
	ElementContentPlus
)

type ElementContentType

type ElementContentType int
const (
	ElementContentPCDATA ElementContentType = iota + 1
	ElementContentElement
	ElementContentSeq
	ElementContentOr
)

type ElementDecl

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

ElementDecl is an xml element declaration from DTD

func (*ElementDecl) AddChild

func (n *ElementDecl) AddChild(cur Node) error

func (*ElementDecl) AddContent

func (n *ElementDecl) AddContent(b []byte) error

func (*ElementDecl) AddSibling

func (n *ElementDecl) AddSibling(cur Node) error

func (ElementDecl) Content

func (n ElementDecl) Content() []byte

func (ElementDecl) FirstChild

func (n ElementDecl) FirstChild() Node

func (ElementDecl) LastChild

func (n ElementDecl) LastChild() Node

func (ElementDecl) LocalName

func (n ElementDecl) LocalName() string

func (ElementDecl) Name

func (n ElementDecl) Name() string

func (ElementDecl) NextSibling

func (n ElementDecl) NextSibling() Node

func (ElementDecl) OwnerDocument

func (n ElementDecl) OwnerDocument() *Document

func (ElementDecl) Parent

func (n ElementDecl) Parent() Node

func (ElementDecl) PrevSibling

func (n ElementDecl) PrevSibling() Node

func (*ElementDecl) Replace

func (n *ElementDecl) Replace(cur Node)

func (*ElementDecl) SetNextSibling

func (n *ElementDecl) SetNextSibling(cur Node)

func (*ElementDecl) SetOwnerDocument

func (n *ElementDecl) SetOwnerDocument(doc *Document)

func (*ElementDecl) SetParent

func (n *ElementDecl) SetParent(cur Node)

func (*ElementDecl) SetPrevSibling

func (n *ElementDecl) SetPrevSibling(cur Node)

func (*ElementDecl) SetTreeDoc

func (n *ElementDecl) SetTreeDoc(doc *Document)

func (ElementDecl) Type

func (n ElementDecl) Type() ElementType

type ElementType

type ElementType int
const (
	ElementNode ElementType = iota + 1
	AttributeNode
	TextNode
	CDATASectionNode
	EntityRefNode
	EntityNode
	ProcessingInstructionNode
	CommentNode
	DocumentNode
	DocumentTypeNode
	DocumentFragNode
	NotationNode
	HTMLDocumentNode
	DTDNode
	ElementDeclNode
	AttributeDeclNode
	EntityDeclNode
	NamespaceDeclNode
	XIncludeStartNode
	XIncludeEndNode

	// This doesn't exist in libxml2. Do we need it?
	NamespaceNode
)

func (ElementType) String

func (i ElementType) String() string

type ElementTypeVal

type ElementTypeVal int

ElementTypeVal represents the different possibilities for an element content type.

const (
	UndefinedElementType ElementTypeVal = iota
	EmptyElementType
	AnyElementType
	MixedElementType
	ElementElementType
)

type Entity

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

func (*Entity) AddChild

func (e *Entity) AddChild(cur Node) error

func (*Entity) AddContent

func (e *Entity) AddContent(b []byte) error

func (*Entity) AddSibling

func (e *Entity) AddSibling(cur Node) error

func (*Entity) Checked

func (e *Entity) Checked() bool

func (*Entity) Content

func (e *Entity) Content() []byte

func (*Entity) EntityType

func (e *Entity) EntityType() int

func (*Entity) MarkChecked

func (e *Entity) MarkChecked()

func (Entity) Name

func (n Entity) Name() string

func (Entity) Namespace

func (n Entity) Namespace() *Namespace

func (Entity) Namespaces

func (n Entity) Namespaces() []*Namespace

func (Entity) Prefix

func (n Entity) Prefix() string

func (*Entity) Replace

func (e *Entity) Replace(cur Node)

func (*Entity) SetNamespace

func (n *Entity) SetNamespace(prefix, uri string, activate ...bool) error

func (*Entity) SetOrig

func (e *Entity) SetOrig(s string)

func (*Entity) SetTreeDoc

func (n *Entity) SetTreeDoc(doc *Document)

func (Entity) URI

func (n Entity) URI() string

type EntityRef

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

func (*EntityRef) AddChild

func (e *EntityRef) AddChild(cur Node) error

func (*EntityRef) AddContent

func (e *EntityRef) AddContent(b []byte) error

func (*EntityRef) AddSibling

func (e *EntityRef) AddSibling(cur Node) error

func (EntityRef) Name

func (n EntityRef) Name() string

func (EntityRef) Namespace

func (n EntityRef) Namespace() *Namespace

func (EntityRef) Namespaces

func (n EntityRef) Namespaces() []*Namespace

func (EntityRef) Prefix

func (n EntityRef) Prefix() string

func (*EntityRef) Replace

func (e *EntityRef) Replace(cur Node)

func (*EntityRef) SetNamespace

func (n *EntityRef) SetNamespace(prefix, uri string, activate ...bool) error

func (*EntityRef) SetTreeDoc

func (n *EntityRef) SetTreeDoc(doc *Document)

func (EntityRef) URI

func (n EntityRef) URI() string

type EntityType

type EntityType int
const (
	InternalGeneralEntity EntityType = iota + 1
	ExternalGeneralParsedEntity
	ExternalGeneralUnparsedEntity
	InternalParameterEntity
	ExternalParameterEntity
	InternalPredefinedEntity
)

type Enumeration

type Enumeration []string

type ErrAttrNotFound

type ErrAttrNotFound struct {
	Token string
}

func (ErrAttrNotFound) Error

func (e ErrAttrNotFound) Error() string

type ErrDTDDupToken

type ErrDTDDupToken struct {
	Name string
}

func (ErrDTDDupToken) Error

func (e ErrDTDDupToken) Error() string

type ErrParseError

type ErrParseError struct {
	Column     int
	Err        error
	Location   int
	Line       string
	LineNumber int
}

func (ErrParseError) Error

func (e ErrParseError) Error() string

type ErrUnimplemented

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

func (ErrUnimplemented) Error

func (e ErrUnimplemented) Error() string

type LoadSubsetOption

type LoadSubsetOption int
const (
	DetectIDs LoadSubsetOption = 1<<iota + 1
	CompleteAttrs
	SkipIDs
)

func (LoadSubsetOption) IsSet

func (*LoadSubsetOption) Set

type Namespace

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

func (Namespace) Prefix

func (n Namespace) Prefix() string

func (Namespace) URI

func (n Namespace) URI() string

type NamespaceContainer

type NamespaceContainer interface {
	Namespaces() []*Namespace
}

type Namespacer

type Namespacer interface {
	Namespace() *Namespace
	Namespaces() []*Namespace
	Prefix() string
	URI() string
	LocalName() string
}

Nemaspacer is an interface for things that has a namespace prefix and uri

type Node

type Node interface {
	AddChild(Node) error
	AddContent([]byte) error
	AddSibling(Node) error
	Content() []byte
	FirstChild() Node
	LastChild() Node
	Name() string
	NextSibling() Node
	OwnerDocument() *Document
	Parent() Node
	PrevSibling() Node
	Replace(Node)
	SetNextSibling(Node)
	SetOwnerDocument(doc *Document)
	SetParent(Node)
	SetPrevSibling(Node)
	SetTreeDoc(doc *Document)
	Type() ElementType
	// contains filtered or unexported methods
}

type ParseOption

type ParseOption int
const (
	ParseRecover   ParseOption = 1 << iota /* recover on errors */
	ParseNoEnt                             /* substitute entities */
	ParseDTDLoad                           /* load the external subset */
	ParseDTDAttr                           /* default DTD attributes */
	ParseDTDValid                          /* validate with the DTD */
	ParseNoError                           /* suppress error reports */
	ParseNoWarning                         /* suppress warning reports */
	ParsePedantic                          /* pedantic error reporting */
	ParseNoBlanks                          /* remove blank nodes */
	// gap here: ParseSAX1 is not implemented
	ParseXInclude   ParseOption = 1<<iota + 10 /* Implement XInclude substitition  */
	ParseNoNet                                 /* Forbid network access */
	ParseNoDict                                /* Do not reuse the context dictionnary */
	ParseNsClean                               /* remove redundant namespaces declarations */
	ParseNoCDATA                               /* merge CDATA as text nodes */
	ParseNoXIncNode                            /* do not generate XINCLUDE START/END nodes */
	ParseCompact                               /* compact small text nodes; no modification of the tree allowed afterwards (will possibly crash if you try to modify the tree) */
	// ParseOld10 is not implemented
	ParseNoBaseFix /* do not fixup XINCLUDE xml:base uris */
	ParseHuge      /* relax any hardcoded limit from the parser */
	// ParseOldSAX is not implemented
	ParseIgnoreEnc ParseOption = 1<<iota + 21 /* ignore internal document encoding hint */
	ParseBigLines  ParseOption = 1 << 22      /* Store big lines numbers in text PSVI field */
)

Note: Many of these are totally unimplemented at this point

func (ParseOption) IsSet

func (p ParseOption) IsSet(n ParseOption) bool

func (*ParseOption) Set

func (p *ParseOption) Set(n ParseOption)

type Parser

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

func NewParser

func NewParser() *Parser

func (*Parser) Parse

func (p *Parser) Parse(b []byte) (*Document, error)

func (*Parser) SetSAXHandler

func (p *Parser) SetSAXHandler(s sax.SAX2Handler)

type ProcessingInstruction

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

func (*ProcessingInstruction) AddChild

func (p *ProcessingInstruction) AddChild(cur Node) error

func (*ProcessingInstruction) AddContent

func (p *ProcessingInstruction) AddContent(b []byte) error

func (*ProcessingInstruction) AddSibling

func (p *ProcessingInstruction) AddSibling(cur Node) error

func (ProcessingInstruction) Content

func (n ProcessingInstruction) Content() []byte

func (ProcessingInstruction) FirstChild

func (n ProcessingInstruction) FirstChild() Node

func (ProcessingInstruction) LastChild

func (n ProcessingInstruction) LastChild() Node

func (ProcessingInstruction) LocalName

func (n ProcessingInstruction) LocalName() string

func (ProcessingInstruction) Name

func (n ProcessingInstruction) Name() string

func (ProcessingInstruction) NextSibling

func (n ProcessingInstruction) NextSibling() Node

func (ProcessingInstruction) OwnerDocument

func (n ProcessingInstruction) OwnerDocument() *Document

func (ProcessingInstruction) Parent

func (n ProcessingInstruction) Parent() Node

func (ProcessingInstruction) PrevSibling

func (n ProcessingInstruction) PrevSibling() Node

func (*ProcessingInstruction) Replace

func (p *ProcessingInstruction) Replace(cur Node)

func (*ProcessingInstruction) SetNextSibling

func (n *ProcessingInstruction) SetNextSibling(cur Node)

func (*ProcessingInstruction) SetOwnerDocument

func (n *ProcessingInstruction) SetOwnerDocument(doc *Document)

func (*ProcessingInstruction) SetParent

func (n *ProcessingInstruction) SetParent(cur Node)

func (*ProcessingInstruction) SetPrevSibling

func (n *ProcessingInstruction) SetPrevSibling(cur Node)

func (*ProcessingInstruction) SetTreeDoc

func (p *ProcessingInstruction) SetTreeDoc(doc *Document)

func (*ProcessingInstruction) Type

type SubstitutionType

type SubstitutionType int
const (
	SubstituteNone SubstitutionType = iota
	SubstituteRef
	SubstitutePERef
	SubstituteBoth
)

type Text

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

Text is just a wrapper around Node so that we can use Go-ish type checks

func (*Text) AddChild

func (n *Text) AddChild(cur Node) error

func (*Text) AddContent

func (n *Text) AddContent(b []byte) error

func (*Text) AddSibling

func (n *Text) AddSibling(cur Node) error

func (Text) Content

func (n Text) Content() []byte

func (Text) Name

func (n Text) Name() string

func (Text) Namespace

func (n Text) Namespace() *Namespace

func (Text) Namespaces

func (n Text) Namespaces() []*Namespace

func (Text) Prefix

func (n Text) Prefix() string

func (*Text) Replace

func (n *Text) Replace(cur Node)

func (*Text) SetNamespace

func (n *Text) SetNamespace(prefix, uri string, activate ...bool) error

func (*Text) SetTreeDoc

func (n *Text) SetTreeDoc(doc *Document)

func (Text) URI

func (n Text) URI() string

type TreeBuilder

type TreeBuilder struct {
}

func NewTreeBuilder

func NewTreeBuilder() *TreeBuilder

func (*TreeBuilder) AttributeDecl

func (t *TreeBuilder) AttributeDecl(ctxif sax.Context, eName string, aName string, typ int, deftype int, value string, enumif sax.Enumeration) error

func (*TreeBuilder) CDataBlock

func (t *TreeBuilder) CDataBlock(_ sax.Context, data []byte) error

func (*TreeBuilder) Characters

func (t *TreeBuilder) Characters(ctxif sax.Context, data []byte) error

func (*TreeBuilder) Comment

func (t *TreeBuilder) Comment(ctxif sax.Context, data []byte) error

func (*TreeBuilder) ElementDecl

func (t *TreeBuilder) ElementDecl(ctxif sax.Context, name string, typ int, content sax.ElementContent) error

func (*TreeBuilder) EndDTD

func (t *TreeBuilder) EndDTD(ctxif sax.Context) error

func (*TreeBuilder) EndDocument

func (t *TreeBuilder) EndDocument(ctxif sax.Context) error

func (*TreeBuilder) EndElementNS

func (t *TreeBuilder) EndElementNS(ctxif sax.Context, localname, prefix, uri string) error

func (*TreeBuilder) EndEntity

func (t *TreeBuilder) EndEntity(ctxif sax.Context, name string) error

func (*TreeBuilder) EntityDecl

func (t *TreeBuilder) EntityDecl(ctxif sax.Context, name string, typ int, publicID string, systemID string, notation string) error

func (*TreeBuilder) Error

func (t *TreeBuilder) Error(ctxif sax.Context, message string, args ...interface{}) error

func (*TreeBuilder) ExternalEntityDecl

func (t *TreeBuilder) ExternalEntityDecl(ctxif sax.Context, name string, publicID string, systemID string) error

func (*TreeBuilder) ExternalSubset

func (t *TreeBuilder) ExternalSubset(ctxif sax.Context, name, eid, uri string) error

func (*TreeBuilder) GetEntity

func (t *TreeBuilder) GetEntity(ctxif sax.Context, name string) (ent sax.Entity, err error)

func (*TreeBuilder) GetExternalSubset

func (t *TreeBuilder) GetExternalSubset(ctxif sax.Context, name string, baseURI string) error

func (*TreeBuilder) GetParameterEntity

func (t *TreeBuilder) GetParameterEntity(ctxif sax.Context, name string) (sax.Entity, error)

func (*TreeBuilder) HasExternalSubset

func (t *TreeBuilder) HasExternalSubset(ctxif sax.Context) (bool, error)

func (*TreeBuilder) HasInternalSubset

func (t *TreeBuilder) HasInternalSubset(ctxif sax.Context) (bool, error)

func (*TreeBuilder) IgnorableWhitespace

func (t *TreeBuilder) IgnorableWhitespace(ctxif sax.Context, content []byte) error

func (*TreeBuilder) InternalEntityDecl

func (t *TreeBuilder) InternalEntityDecl(ctxif sax.Context, name string, value string) error

func (*TreeBuilder) InternalSubset

func (t *TreeBuilder) InternalSubset(ctxif sax.Context, name, eid, uri string) error

func (*TreeBuilder) IsStandalone

func (t *TreeBuilder) IsStandalone(ctxif sax.Context) (bool, error)

func (*TreeBuilder) NotationDecl

func (t *TreeBuilder) NotationDecl(ctxif sax.Context, name string, publicID string, systemID string) error

func (*TreeBuilder) ProcessingInstruction

func (t *TreeBuilder) ProcessingInstruction(ctxif sax.Context, target, data string) error

func (*TreeBuilder) Reference

func (t *TreeBuilder) Reference(ctxif sax.Context, name string) error

func (*TreeBuilder) ResolveEntity

func (t *TreeBuilder) ResolveEntity(ctxif sax.Context, publicID string, systemID string) (sax.ParseInput, error)

func (*TreeBuilder) SetDocumentLocator

func (t *TreeBuilder) SetDocumentLocator(ctxif sax.Context, loc sax.DocumentLocator) error

func (*TreeBuilder) SkippedEntity

func (t *TreeBuilder) SkippedEntity(ctxif sax.Context, name string) error

func (*TreeBuilder) StartDTD

func (t *TreeBuilder) StartDTD(ctxif sax.Context, name string, publicID string, systemID string) error

func (*TreeBuilder) StartDocument

func (t *TreeBuilder) StartDocument(ctxif sax.Context) error

func (*TreeBuilder) StartElementNS

func (t *TreeBuilder) StartElementNS(ctxif sax.Context, localname, prefix, uri string, namespaces []sax.Namespace, attrs []sax.Attribute) error

func (*TreeBuilder) StartEntity

func (t *TreeBuilder) StartEntity(ctxif sax.Context, name string) error

func (*TreeBuilder) UnparsedEntityDecl

func (t *TreeBuilder) UnparsedEntityDecl(ctxif sax.Context, name string, publicID string, systemID string, notation string) error

type WalkFunc

type WalkFunc func(Node) error

Directories

Path Synopsis
cmd
Package encoding wraps around the various encoding stuff in golang.org/x/text/encoding.
Package encoding wraps around the various encoding stuff in golang.org/x/text/encoding.
internal
WARNING: This file is generated by gencbsax.pl
WARNING: This file is generated by gencbsax.pl

Jump to

Keyboard shortcuts

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