diff --git a/common/data/xml/monster_refresh.go b/common/data/xml/monster_refresh.go index 83edde55..76add160 100644 --- a/common/data/xml/monster_refresh.go +++ b/common/data/xml/monster_refresh.go @@ -4,10 +4,16 @@ import ( "github.com/ECUST-XX/xml" ) +type xmls struct { + Text string `xml:",chardata"` + Version string `xml:"comment"` + + SuperMaps SuperMaps `xml:"superMaps"` +} type SuperMaps struct { XMLName xml.Name `xml:"superMaps"` - //Text string `xml:",chardata"` - Maps []Maps `xml:"maps"` + Text string `xml:",comment"` + Maps []Maps `xml:"maps"` } type Maps struct { diff --git a/common/data/xml/monster_refresh_test.go b/common/data/xml/monster_refresh_test.go index 42e97523..46387aec 100644 --- a/common/data/xml/monster_refresh_test.go +++ b/common/data/xml/monster_refresh_test.go @@ -67,6 +67,7 @@ func Test_main(t *testing.T) { // }) tf, _ := xml.MarshalIndentShortForm(tt, " ", " ") fmt.Println(string(tf)) + } func main1() { @@ -124,3 +125,35 @@ func main1() { // fmt.Printf("#%d %s\n", i, n.InnerText()) // } } + +func TestMMMs(t *testing.T) { + + decoder := xml.NewDecoder(strings.NewReader(s)) + var rootComments []string + rootFound := false + + for { + token, err := decoder.Token() + if err != nil { + break + } + + switch t := token.(type) { + case xml.StartElement: + // 遇到根元素开始标签后停止收集注释 + rootFound = true + fmt.Printf("找到根元素: %s\n", t.Name.Local) + case xml.Comment: + if !rootFound { + // 保存根元素前的注释 + rootComments = append(rootComments, string(t)) + } + } + } + + // 输出捕获的根注释 + fmt.Println("\n根注释内容:") + for _, comment := range rootComments { + fmt.Println(strings.TrimSpace(comment)) + } +}