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 ¶
- func ParseFile(filename string, cb SaxCallbacks) error
- func ParseMem(buf bytes.Buffer, cb SaxCallbacks) error
- func UnpackString(ch unsafe.Pointer, chlen int) string
- type CharactersFunc
- type CharactersRawFunc
- type EndDocumentFunc
- type EndElementFunc
- type SaxCallbacks
- type StartDocumentFunc
- type StartElementFunc
- type StartElementNoAttrFunc
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.
Types ¶
type CharactersFunc ¶
type CharactersFunc func(contents string)
type CharactersRawFunc ¶
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 StartElementNoAttrFunc ¶
type StartElementNoAttrFunc func(name string)