Skip to content

Commit

Permalink
Remove trailing print and add GetAttribute func
Browse files Browse the repository at this point in the history
  • Loading branch information
garaekz committed Jul 18, 2022
1 parent 3c9227a commit 7d637aa
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ _testmain.go
*.test
*.prof

.tests
# Local folder to test functionality in use cases
tests
28 changes: 2 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,10 @@ Parsing the value of a style element.

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

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

// Output:
// SVG width: 100
// Circle fill: red
}

### License

The MIT License (MIT)

Copyright (c) 2015 Ekaterina Goranova

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 0 additions & 3 deletions find.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package svgparser

import "fmt"

// FindID finds the first child with the specified ID.
func (e *Element) FindID(id string) *Element {
for _, child := range e.Children {
Expand Down Expand Up @@ -33,7 +31,6 @@ func (e *Element) FindAll(name string) []*Element {
func (e *Element) FindAllBySpaceAndLocalName(space, localName string) []*Element {
var elements []*Element
for _, child := range e.Children {
fmt.Printf("%+v\n", child.Name)
if child.Name.Space == space && child.Name.Local == localName {
elements = append(elements, child)
}
Expand Down
10 changes: 10 additions & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,13 @@ func Parse(source io.Reader, validate bool) (*Element, error) {
}
return element, nil
}

// GetAttribute returns the value of the attribute with the given name.
func (e *Element) GetAttribute(name string) string {
for _, attr := range e.Attributes {
if attr.Name.Local == name {
return attr.Value
}
}
return ""
}

0 comments on commit 7d637aa

Please sign in to comment.