background/test/xml_test.go

42 lines
684 B
Go
Raw Normal View History

2021-02-06 16:48:29 +00:00
package test
import (
2021-05-07 16:15:04 +00:00
"encoding/xml"
"log"
"os"
2021-02-06 16:48:29 +00:00
"testing"
)
type Sub struct {
A string `xml:"a"`
}
type Test struct {
A int32 `json:"a" xml:"a"`
B bool `json:"b" xml:"b"`
C string `json:"c" xml:"c"`
D Sub `xml:"sub"`
}
func TestXml(t *testing.T) {
2021-05-07 16:15:04 +00:00
xmlFile, err := os.Open("process.ui")
if err != nil {
log.Fatal(err)
}
defer xmlFile.Close()
decoder := xml.NewDecoder(xmlFile)
for {
token, _ := decoder.Token()
if token == nil {
break
}
switch startElement := token.(type) {
case xml.StartElement:
t.Log(startElement.Name.Local)
if startElement.Name.Local == "entry" {
// do what you need to do for each entry below
}
}
}
2021-02-06 16:48:29 +00:00
}