feat(common): 添加 XML 根注释解析功能

- 在 monster_refresh.go 中添加 xmls 结构体,用于解析 XML 根注释
- 在 monster_refresh_test.go 中添加 TestMMMs 函数,实现根注释的捕获和输出
- 优化了 XML 解析逻辑,能够正确处理注释内容
This commit is contained in:
2025-07-04 18:53:05 +08:00
parent b00dbc5e00
commit e04b859137
2 changed files with 41 additions and 2 deletions

View File

@@ -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))
}
}