diff --git a/.gitignore b/.gitignore index 5ed7172..5086dde 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,5 @@ _testmain.go *.test *.prof -.tests \ No newline at end of file +# Local folder to test functionality in use cases +tests \ No newline at end of file diff --git a/README.md b/README.md index 89b08cf..8e3fc35 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/find.go b/find.go index eecae44..e04e304 100644 --- a/find.go +++ b/find.go @@ -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 { @@ -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) } diff --git a/parser.go b/parser.go index 711dc48..3a1f01f 100644 --- a/parser.go +++ b/parser.go @@ -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 "" +}