-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.go
51 lines (45 loc) · 1.22 KB
/
functions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package soap
import (
"fmt"
"strconv"
"strings"
"github.com/antchfx/xmlquery"
)
// GetStringFromXML ...
func GetStringFromXML(node *xmlquery.Node, selector string) string {
childNode := xmlquery.FindOne(node, selector)
if childNode != nil {
return childNode.InnerText()
}
return ""
}
// GetIntFromXML doc ..
func GetIntFromXML(node *xmlquery.Node, selector string) (int, error) {
childNode := xmlquery.FindOne(node, selector)
if childNode != nil {
value, err := strconv.Atoi(childNode.InnerText())
if err != nil {
return 0, fmt.Errorf("Couldn't parse value from selector: %s. [%+v]", selector, childNode)
}
return value, nil
}
return 0, nil
}
// GetIntFromXML doc ..
func getFloatFromXML(node *xmlquery.Node, selector string) (float64, error) {
childNode := xmlquery.FindOne(node, selector)
if childNode != nil {
value, err := strconv.ParseFloat(childNode.InnerText(), 32)
if err != nil {
return 0, fmt.Errorf("Couldn't parse amount from selector: %s. [%+v]", selector, childNode)
}
return value, nil
}
return 0, nil
}
// CleanXML doc ..
func CleanXML(request string) string {
request = strings.Replace(request, "<![CDATA[", "", -1)
request = strings.Replace(request, "]]>", "", -1)
return request
}