svgparser

package module
v0.0.0-...-be2419b Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2020 License: MIT Imports: 6 Imported by: 0

README

svgparser

Library for parsing and manipulating SVG files.

Installation
go get bitbucket.org/afiszone/svgparser
Features
Validation

Checks if the SVG input is valid according to the W3C Recommendation.

Find functionality

Provides capability to search for SVG elements by id or element name.

Path Parser

Parsing the 'd' attribute of a path element into a structure containing all subpaths with their commands and parameters.

Style Parser

Parsing the value of a style element.

Example
func ExampleParse() {
	svg := `
		<svg width="100" height="100">
			<circle cx="50" cy="50" r="40" fill="red" />
		</svg>
	`
	reader := strings.NewReader(svg)

	element, _ := svgparser.Parse(reader, false)

	fmt.Printf("SVG width: %s", element.Attributes["width"])
	fmt.Printf("Circle fill: %s", element.Children[0].Attributes["fill"])

	// Output:
	// SVG width: 100
	// Circle fill: red
}
License
Clone and edit form github.com/catiepg/svgparser

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

type Element struct {
	Name       string
	Attributes map[string]string
	Children   []*Element
	Content    string
}

Element is a representation of an SVG element.

func DecodeFirst

func DecodeFirst(decoder *xml.Decoder) (*Element, error)

DecodeFirst creates the first element from the decoder.

func NewElement

func NewElement(token xml.StartElement) *Element

NewElement creates element from decoder token.

func Parse

func Parse(source io.Reader, validate bool) (*Element, error)

Parse creates an Element instance from an SVG input.

func (*Element) Compare

func (e *Element) Compare(o *Element) bool

Compare compares two elements.

func (*Element) Decode

func (e *Element) Decode(decoder *xml.Decoder) error

Decode decodes the child elements of element.

func (*Element) FindAll

func (e *Element) FindAll(name string) []*Element

FindAll finds all children with the given name.

func (*Element) FindID

func (e *Element) FindID(id string) *Element

FindID finds the first child with the specified ID.

type ValidationError

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

ValidationError contains errors which have occured when parsing svg input.

func (ValidationError) Error

func (err ValidationError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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