Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Element ¶
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/JoshVarga/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) FindAll ¶
FindAll finds all children with the given name.
Example ¶
package main
import (
"fmt"
"strings"
"github.com/JoshVarga/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/JoshVarga/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
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
Click to show internal directories.
Click to hide internal directories.