background/test/xml_test.go

42 lines
684 B
Go

package test
import (
"encoding/xml"
"log"
"os"
"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) {
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
}
}
}
}