xsd

package
v0.0.0-...-e6d9de6 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package xsd contains some of the tools available from libxml2 that allows you to validate your XML against an XSD

This is basically all you need to do:

schema, err := xsd.Parse(xsdsrc)
if err != nil {
    panic(err)
}
defer schema.Free()
if err := schema.Validate(doc); err != nil{
    for _, e := range err.(SchemaValidationErr).Error() {
         println(e.Error())
    }
}

Index

Constants

View Source
const ValueVCCreate = 1

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option = option.Interface

func WithPath

func WithPath(path string) Option

WithPath provides a hint to the XSD parser as to where the document being parsed is located at.

This is useful when you must resolve relative paths inside a document, because to use relative paths the parser needs to know the reference location (i.e. location of the document being parsed). In case where you are parsing using `ParseFromFile()` this is handled automatically by the `ParseFromFile` method, but if you are using `Parse` method this is required

If the path is provided as a relative path, the current directory should be obtainable via `os.Getwd` when this call is made, otherwise path resolution may fail in weird ways.

func WithURI

func WithURI(v string) Option

type Schema

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

Schema represents an XML schema.

func Parse

func Parse(buf []byte, options ...Option) (*Schema, error)

func ParseFromFile

func ParseFromFile(path string) (*Schema, error)

ParseFromFile is used to parse an XML schema using only the file path. Make sure to call Free() on the instance when you are done with it.

func (*Schema) Free

func (s *Schema) Free()

Free frees the underlying C struct

func (*Schema) Pointer

func (s *Schema) Pointer() uintptr

Pointer returns the underlying C struct

func (*Schema) Validate

func (s *Schema) Validate(d types.Document, options ...int) error

Validate takes in a XML document and validates it against the schema. If there are any problems, and error is returned.

type SchemaValidationError

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

SchemaValidationError is returned when the Validate() function finds errors. When there are multiple errors, you may access them using the Errors() method

func (SchemaValidationError) Error

func (sve SchemaValidationError) Error() string

Error method fulfils the error interface

func (SchemaValidationError) Errors

func (sve SchemaValidationError) Errors() []error

Errors returns the list of errors found

Jump to

Keyboard shortcuts

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