From 80180f55f3b3cea51d71f323dd91f2d16bba22aa Mon Sep 17 00:00:00 2001 From: "DESKTOP-4RNDQIC\\29019" <290198252@qq.com> Date: Sat, 8 May 2021 00:15:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0qt=20.ui=E8=BD=ACcss=20?= =?UTF-8?q?=E5=B0=8F=E5=B7=A5=E5=85=B7=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 41 +++++++++++++++++++++++++++++++++++++- process.ui | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ test/xml_test.go | 35 +++++++++++++++++++++------------ 3 files changed, 113 insertions(+), 14 deletions(-) create mode 100644 process.ui diff --git a/main.go b/main.go index 461bf69..5773d68 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( _ "background/docs" "background/logs" "background/model" + "encoding/xml" "log" "os" "strconv" @@ -91,9 +92,47 @@ func InitElasticSearch() { func InitLogs() { logs.Init(config.GetLogConfig().Dir, config.GetLogConfig().File, config.GetLogConfig().Level, config.GetLogConfig().SaveFile) } + + +func getAttr(name string, attr []xml.Attr) string { + for _, a := range attr { + if a.Name.Local == name { + return a.Value + } + } + return "" +} + + +func TestUI(){ + 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: + log.Print(startElement.Name.Local) + if(startElement.Name.Local == "widget"){ + log.Print(getAttr("name",startElement.Attr)) + } + break + case xml.EndElement: + log.Print(startElement.Name.Local) + break + } + } +} + func main() { log.Print("gid is", os.Getegid()) - + TestUI() InitConfig() InitLogs() InitRedisConfig() diff --git a/process.ui b/process.ui new file mode 100644 index 0000000..2c0b1d0 --- /dev/null +++ b/process.ui @@ -0,0 +1,51 @@ + + + Process + + + + 0 + 0 + 324 + 88 + + + + + 0 + 0 + + + + Dialog + + + + + 30 + 50 + 281 + 31 + + + + 24 + + + + + + 120 + 30 + 121 + 16 + + + + 正在加载数据 + + + + + + diff --git a/test/xml_test.go b/test/xml_test.go index e64a66e..f8b42be 100644 --- a/test/xml_test.go +++ b/test/xml_test.go @@ -1,6 +1,9 @@ package test import ( + "encoding/xml" + "log" + "os" "testing" ) @@ -15,18 +18,24 @@ type Test struct { } func TestXml(t *testing.T) { - // x := map[string]interface{}{} - // x["map"] = 1 - // x["ss"] = 2 - // test := Test{A: 1, B: false, C: "hell", D: Sub{A: "aa"}} - // bytes, e := xml.Marshal(&test) - // if nil != e { - // t.Error(e.Error()) + 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 + } + } + } - // } - // bytes, e = xml.Marshal(&x) - // if nil != e { - // t.Error(e.Error()) - - // } }