Documentation ¶
Index ¶
- func EncodeXML(r *Element, e *xml.Encoder, excludes []string) (err error)
- func FindAllLinkedIDs(r *Element, id string) []string
- func FindAllLinkedUUIDs(r *Element, uuid string) []string
- type Element
- func (e *Element) Ancestors() []*Element
- func (e *Element) Compare(o *Element) bool
- func (e *Element) Compose(w io.Writer) error
- func (e *Element) ComposeExcludes(w io.Writer, uuids []string) error
- func (e *Element) Decode(decoder *xml.Decoder) error
- func (e *Element) Descendants() []*Element
- func (e *Element) FindAll(name string) []*Element
- func (e *Element) FindID(id string) *Element
- func (e *Element) FindLinkedIDs() []string
- func (e *Element) FindUUID(uuid string) *Element
- func (e *Element) Generations() []*Element
- func (e *Element) Hash() string
- func (e *Element) SelectByUUIDs(uuids []string) *Element
- func (e *Element) XMLElement() xml.StartElement
- type ValidationError
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindAllLinkedIDs ¶ added in v1.4.0
FindAllLinkedIDs finds related linked ID recursively
func FindAllLinkedUUIDs ¶ added in v1.4.0
FindAllLinkedUUIDs finds related linked ID recursively
Types ¶
type Element ¶
type Element struct { UUID string Name string Attributes map[string]string Parent *Element Children []*Element Content string }
Element is a representation of an SVG element.
func DecodeFirst ¶
DecodeFirst creates the first element from the decoder.
func NewElement ¶
func NewElement(token xml.StartElement) *Element
NewElement creates element from decoder token.
func Parse ¶
Parse creates an Element instance from an SVG input.
Example ¶
package main import ( "fmt" "strings" "github.com/chikamim/svgparser" ) func main() { 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\n", element.Attributes["width"]) fmt.Printf("Circle fill: %s", element.Children[0].Attributes["fill"]) }
Output: SVG width: 100 Circle fill: red
func (*Element) ComposeExcludes ¶ added in v1.4.0
func (*Element) Descendants ¶ added in v1.4.0
Descendants returns descendants' elements
func (*Element) FindAll ¶
FindAll finds all children with the given name.
Example ¶
package main import ( "fmt" "strings" "github.com/chikamim/svgparser" ) func main() { svg := ` <svg width="1000" height="600"> <rect fill="#000" width="5" height="3"/> <rect fill="#444" width="5" height="2" y="1"/> <rect fill="#888" width="5" height="1" y="2"/> </svg> ` reader := strings.NewReader(svg) element, _ := svgparser.Parse(reader, false) rectangles := element.FindAll("rect") fmt.Printf("First child fill: %s\n", rectangles[0].Attributes["fill"]) fmt.Printf("Second child height: %s", rectangles[1].Attributes["height"]) }
Output: First child fill: #000 Second child height: 2
func (*Element) FindID ¶
FindID finds the first child with the specified ID.
Example ¶
package main import ( "fmt" "strings" "github.com/chikamim/svgparser" ) func main() { svg := ` <svg width="1000" height="600"> <rect id="black" fill="#000" width="5" height="3"/> <rect id="gray" fill="#888" width="5" height="2" y="1"/> <rect id="white" fill="#fff" width="5" height="1" y="2"/> </svg> ` reader := strings.NewReader(svg) element, _ := svgparser.Parse(reader, false) white := element.FindID("white") fmt.Printf("White rect fill: %s", white.Attributes["fill"]) }
Output: White rect fill: #fff
func (*Element) FindLinkedIDs ¶ added in v1.4.0
FindLinkedIDs finds related linked ID
func (*Element) Generations ¶ added in v1.4.0
Generations returns all generations
func (*Element) SelectByUUIDs ¶ added in v1.4.0
SelectByUUIDs filter all children with the given ids.
func (*Element) XMLElement ¶ added in v1.3.0
func (e *Element) XMLElement() xml.StartElement
XMLElement convert to XMLElement
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