Skip to content

Commit

Permalink
Change GetField to GetValue. GetValue belongs to XMLElement struct.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eloy Franco committed Jul 29, 2019
1 parent f4a2ac3 commit 82331bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions xmlparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (x *XMLParser) Stream() chan *XMLElement {

}

func GetField(element XMLElement, paths []string, indexes []int, attr string) string {
func (element XMLElement) GetValue(paths []string, indexes []int, attr string) string {
if len(indexes) == 0 {
indexes = make([]int, len(paths))
}
Expand All @@ -79,7 +79,7 @@ func GetField(element XMLElement, paths []string, indexes []int, attr string) st
return element.Childs[path][index].Attrs[attr]
}
}
return GetField(element.Childs[path][index], paths, indexes, attr)
return element.Childs[path][index].GetValue(paths, indexes, attr)
} else {
return ""
}
Expand Down
12 changes: 6 additions & 6 deletions xmlparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,27 +236,27 @@ func TestGetField(t *testing.T) {
var found string
p := getparser("examples")
for xml := range p.Stream() {
found = GetField(*xml, []string{"tag1", "tag11"}, []int{}, "")
found = xml.GetValue([]string{"tag1", "tag11"}, []int{}, "")
if found != "InnerText110" {
t.Errorf("tag1>tag11 doesn´t match with expected \n\t Expected: %s \n\t Found: %s", "InnerText110", found)
}
found = GetField(*xml, []string{"tag1", "tag11"}, []int{0, 1}, "")
found = xml.GetValue([]string{"tag1", "tag11"}, []int{0, 1}, "")
if found != "InnerText111" {
t.Errorf("tag1>tag11 doesn´t match with expected \n\t Expected: %s \n\t Found: %s", "InnerText111", found)
}
found = GetField(*xml, []string{"tag1", "tag11"}, []int{1, 0}, "")
found = xml.GetValue([]string{"tag1", "tag11"}, []int{1, 0}, "")
if found != "InnerText2" {
t.Errorf("tag1>tag11 doesn´t match with expected \n\t Expected: %s \n\t Found: %s", "InnerText2", found)
}
found = GetField(*xml, []string{"tag1", "tag12"}, []int{1, 0}, "att1")
found = xml.GetValue([]string{"tag1", "tag12"}, []int{1, 0}, "att1")
if found != "att1" {
t.Errorf("tag1>tag12>@att1 doesn´t match with expected \n\t Expected: %s \n\t Found: %s", "att1", found)
}
found = GetField(*xml, []string{"missingtag", "tag12", "tag13"}, []int{0, 0, 0}, "")
found = xml.GetValue([]string{"missingtag", "tag12", "tag13"}, []int{0, 0, 0}, "")
if found != "" {
t.Errorf("missingtag>tag12>tag13 doesn´t match with expected \n\t Expected: %s \n\t Found: %s", "att1", found)
}
found = GetField(*xml, []string{"tag1", "tag12", "missingtag"}, []int{1, 0, 0}, "att1")
found = xml.GetValue([]string{"tag1", "tag12", "missingtag"}, []int{1, 0, 0}, "att1")
if found != "" {
t.Errorf("tag1>tag12>missingtag>@att1 doesn´t match with expected \n\t Expected: %s \n\t Found: %s", "att1", found)
}
Expand Down

0 comments on commit 82331bf

Please sign in to comment.