Documentation
¶
Overview ¶
The goal of this package is to preload xsd files into memory and to validate xml (fast) using libxml2, like post bodys of xml service endpoints or api routers. At the time of writing, similar packages I found on github either didn't provide error details or got stuck under load. In addition to providing error strings it also exposes some fields of libxml2 return structs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cleanup ¶
func Cleanup()
Cleanup cleans up libxml2 memory and finishes gc goroutine when running.
func InitWithGc ¶
InitWithGc initializes lbxml2 with a goroutine that trims memory and runs the go gc every d duration. Not required but can help to keep the memory footprint at bay when doing tons of validations.
Types ¶
type Libxml2Error ¶
type Libxml2Error struct {
// contains filtered or unexported fields
}
Libxml2Error is returned when a Libxm2 initialization error occured.
type Options ¶
type Options uint8
Options type for parser/validation options.
type StructError ¶
type StructError struct { Code int `json:"code"` Message string `json:"message"` Level int `json:"level"` Line int `json:"line"` NodeName string `json:"node_name"` }
StructError is a subset of libxml2 xmlError struct.
type ValidationError ¶
type ValidationError struct {
Errors []StructError
}
ValidationError is returned when xsd validation caused an error, to access the fields of the Errors slice use type assertion (see example).
func (ValidationError) Error ¶
func (e ValidationError) Error() string
Implementation of the Error interface.
func (ValidationError) String ¶
func (e ValidationError) String() string
Implementation of the Stringer interface. Aggregates line numbers and messages of the Errors slice.
type XmlHandler ¶
type XmlHandler struct {
// contains filtered or unexported fields
}
XmlHandler handles xml parsing and wraps a pointer to libxml2's xmlDocPtr.
func NewXmlHandlerMem ¶
func NewXmlHandlerMem(inXml []byte, options Options) (*XmlHandler, error)
NewXmlHandlerMem creates a xml handler struct. If an error is returned it can be of type Libxml2Error or XmlParserError. Always use the Free() method when done using this handler or memory will be leaking. The go garbage collector will not collect the allocated resources.
func (*XmlHandler) Free ¶
func (xmlHandler *XmlHandler) Free()
Free frees the wrapped xml docPtr, call this when this handler is not needed anymore.
type XmlParserError ¶
type XmlParserError struct {
// contains filtered or unexported fields
}
XmlParserError is returned when xml parsing caused error(s).
type XsdHandler ¶
type XsdHandler struct {
// contains filtered or unexported fields
}
XsdHandler handles schema parsing and validation and wraps a pointer to libxml2's xmlSchemaPtr.
func NewXsdHandlerMem ¶
func NewXsdHandlerMem(inXml []byte, options Options) (*XsdHandler, error)
NewXsdHandlerUrl creates a xsd handler struct from mem instead of location. Always use Free() method when done using this handler or memory will be leaking. If an error is returned it can be of type Libxml2Error or XsdParserError. The go garbage collector will not collect the allocated resources.
func NewXsdHandlerUrl ¶
func NewXsdHandlerUrl(url string, options Options) (*XsdHandler, error)
NewXsdHandlerUrl creates a xsd handler struct. Always use Free() method when done using this handler or memory will be leaking. If an error is returned it can be of type Libxml2Error or XsdParserError. The go garbage collector will not collect the allocated resources.
func (*XsdHandler) Free ¶
func (xsdHandler *XsdHandler) Free()
Free frees the wrapped schemaPtr, call this when this handler is not needed anymore.
func (*XsdHandler) Validate ¶
func (xsdHandler *XsdHandler) Validate(xmlHandler *XmlHandler, options Options) error
Validate validates an xmlHandler against an xsdHandler and returns a ValidationError. If an error is returned it is of type Libxml2Error, XsdParserError, XmlParserError or ValidationError. Both xmlHandler and xsdHandler have to be created first.
func (*XsdHandler) ValidateMem ¶
func (xsdHandler *XsdHandler) ValidateMem(inXml []byte, options Options) error
ValidateMem validates an xml byte slice against an xsdHandler. If an error is returned it can be of type Libxml2Error, XsdParserError, XmlParserError or ValidationError. The xsdHandler has to be created first.
type XsdParserError ¶
type XsdParserError struct {
// contains filtered or unexported fields
}
XsdParserError is returned when xsd parsing caused a error(s).
Directories
¶
Path | Synopsis |
---|---|
examples
|
|
_server/simple
A simple standalone example for xsd validation and http
|
A simple standalone example for xsd validation and http |
_server/simpler
A simpler standalone example for xsd validation and http
|
A simpler standalone example for xsd validation and http |