gosax

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2020 License: Unlicense Imports: 7 Imported by: 0

README

gosax

For some background information, motivation and a basic usage sample see this blog post.

Building

To install libxml2 for development, do:

$ sudo apt-get install libxml2 libxml2-dev

Or build from source. You would need it installed to use gosax.

License

gosax's code is in the public domain (see LICENSE for details). It uses libxml, which has its own (MIT) license.

The pointer directory vendors https://github.com/mattn/go-pointer/ with some modifications. go-pointer has an MIT license, which applies to my version too.

Documentation

Overview

gosax: Go wrapper for libxml SAX.

C helpers for internal use.

Eli Bendersky [https://eli.thegreenplace.net] This code is in the public domain.

gosax: Go wrapper for libxml SAX.

This file contains all the exported functionality of the module.

Eli Bendersky [https://eli.thegreenplace.net] This code is in the public domain.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseFile

func ParseFile(filename string, cb SaxCallbacks) error

ParseFile parses an XML file with the given name using SAX, with cb as the callbacks. The file name is required, rather than a reader, because it gets passed directly to the C layer.

func ParseMem

func ParseMem(buf bytes.Buffer, cb SaxCallbacks) error

A better SAX parsing routine. parse an XML in-memory buffer, with cb as the callbacks.

func UnpackString

func UnpackString(ch unsafe.Pointer, chlen int) string

UnpackString unpacks the opaque ch, chlen pair (that some callbacks in this package may create) into a Go string.

Types

type CharactersFunc

type CharactersFunc func(contents string)

type CharactersRawFunc

type CharactersRawFunc func(ch unsafe.Pointer, chlen int)

type EndDocumentFunc

type EndDocumentFunc func()

type EndElementFunc

type EndElementFunc func(name string)

type SaxCallbacks

type SaxCallbacks struct {
	// StartDocument is invoked on the "start document" event.
	StartDocument StartDocumentFunc

	// EndDocument is invoked on the "end document" event
	EndDocument EndDocumentFunc

	// StartElement is invoked whenever the beginning of a new element is found.
	// name will be the element name, and attrs a slice of attributes where
	// attribute names alternate with values. For example, given the element
	// <elem foo="bar" id="100"> the callback will get name="elem" and
	// attrs=["foo", "bar", "id", "100"].
	StartElement StartElementFunc

	// StartElementNoAttr will override StartElement, if set. When you don't
	// care about the attributes of an element, use this one - it will be faster
	// because it doesn't have to do attribute unpacking, which is expensive.
	StartElementNoAttr StartElementNoAttrFunc

	// EndElement is invoked at the end of parsing an element (after closing tag
	// has been processed), with name being the element name.
	EndElement EndElementFunc

	// Characters is invoked on character data inside elements. contents is the
	// data, as string. Note that this callback may be invoked multiple times
	// within a single tag.
	Characters CharactersFunc

	// CharactersRaw will override Characters, if set. It doesn't translate XML
	// data into a Go string, but leaves it as an opaque pair of (ch, chlen),
	// which you could use UnpackString to convert to a string if needed. This
	// could be a useful optimization if you're only occasionally interested in
	// the contents of character data.
	CharactersRaw CharactersRawFunc
}

SaxCallbacks collects callback functions to invoke on SAX events. Only populate callbacks you're interested in - callbacks left as nil will not be registered with the C layer and may save processing time. Some callbacks override others for optimization purposes - check the comments for more information.

type StartDocumentFunc

type StartDocumentFunc func()

type StartElementFunc

type StartElementFunc func(name string, attrs []string)

type StartElementNoAttrFunc

type StartElementNoAttrFunc func(name string)

Directories

Path Synopsis
gosax: example of using gosax.
gosax: example of using gosax.
package pointer helps pass arbitrary Go values to C code and back.
package pointer helps pass arbitrary Go values to C code and back.

Jump to

Keyboard shortcuts

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