- init
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details

master v1.0.0
李光春 2 years ago
commit 6470d250fb

@ -0,0 +1,17 @@
kind: pipeline
type: docker
name: clone
steps:
- name: Test
image: golang:1.18
commands:
- go env -w GO111MODULE=on
- go env -w GOPROXY=https://goproxy.cn,direct
- go test -v ./...
- name: Benchmark
image: golang:1.18
commands:
- go env -w GO111MODULE=on
- go env -w GOPROXY=https://goproxy.cn,direct
- go test -bench=. -benchmem

9
.gitignore vendored

@ -0,0 +1,9 @@
.env
.git
.svn
.idea
.vscode
*.log
goinit.sh
gomod.sh
/vendor/

@ -0,0 +1,3 @@
module go.dtapp.net/goxml
go 1.18

@ -0,0 +1,43 @@
package goxml
import (
"encoding/xml"
"io"
"strings"
)
func XmlDecode(data string) map[string]string {
decoder := xml.NewDecoder(strings.NewReader(data))
result := make(map[string]string)
key := ""
for {
token, err := decoder.Token() //读取一个标签或者文本内容
if err == io.EOF {
return result
}
if err != nil {
return result
}
switch tp := token.(type) { //读取的TOKEN可以是以下三种类型StartElement起始标签EndElement结束标签CharData文本内容
case xml.StartElement:
se := xml.StartElement(tp) //强制类型转换
if se.Name.Local != "xml" {
key = se.Name.Local
}
if len(se.Attr) != 0 {
//读取标签属性
}
case xml.EndElement:
ee := xml.EndElement(tp)
if ee.Name.Local == "xml" {
return result
}
case xml.CharData: //文本数据,注意一个结束标签和另一个起始标签之间可能有空格
cd := xml.CharData(tp)
data := strings.TrimSpace(string(cd))
if len(data) != 0 {
result[key] = data
}
}
}
}

@ -0,0 +1,3 @@
package goxml
const Version = "1.0.0"

@ -0,0 +1,7 @@
package goxml
import "testing"
func TestVersion(t *testing.T) {
t.Log(Version)
}
Loading…
Cancel
Save