-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxml.go
53 lines (41 loc) · 1.23 KB
/
xml.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
52
53
package golib
import (
"encoding/xml"
"strconv"
"github.com/antchfx/xmlquery"
)
func AttrByName(attrs []xmlquery.Attr, name string) string {
for _, attr := range attrs {
if attr.Name.Local == name {
return attr.Value
}
}
return ""
}
func XmlStart(name string) xml.StartElement {
return xml.StartElement{Name: xml.Name{Local: name}}
}
func XmlEnd(name string) xml.EndElement {
return xml.EndElement{Name: xml.Name{Local: name}}
}
func XmlSetAttr(start *xml.StartElement, attr xml.Attr) {
start.Attr = append(start.Attr, attr)
}
func XmlAttr(name, value string) xml.Attr {
return xml.Attr{Name: xml.Name{Local: name}, Value: value}
}
func XmlAttrAppend(start *xml.StartElement, name, value string) {
start.Attr = append(start.Attr, XmlAttr(name, value))
}
func XmlAttrInt64(name string, value int64) xml.Attr {
return XmlAttr(name, strconv.FormatInt(value, 10))
}
func XmlAttrInt64Append(start *xml.StartElement, name string, value int64) {
start.Attr = append(start.Attr, XmlAttrInt64(name, value))
}
func XmlAttrInt(name string, value int) xml.Attr {
return XmlAttr(name, strconv.Itoa(value))
}
func XmlAttrIntAppend(start *xml.StartElement, name string, value int) {
start.Attr = append(start.Attr, XmlAttrInt(name, value))
}