package main import ( "fmt" "strings" "testing" "github.com/ECUST-XX/xml" "github.com/antchfx/xmlquery" ) var s = ` ` func Test_main(t *testing.T) { tt := &SuperMaps{} xml.Unmarshal([]byte(s), tt) // tt.Maps = append(tt.Maps, Maps{ // ID: "1", // Name: "传送舱", // // Galaxy: "1", // X: "358", // Y: "46", // }) // tt.Maps = append(tt.Maps, Maps{ // ID: "4", // Name: "船长室", // // Galaxy: "1", // X: "358", // Y: "46", // }) tf, _ := xml.MarshalIndentShortForm(tt, " ", " ") fmt.Println(string(tf)) } func main1() { s := ` ` doc, err := xmlquery.Parse(strings.NewReader(s)) if err != nil { panic(err) } //channel := xmlquery.FindOne(doc, "//superMaps") // if n := channel.SelectElement("maps"); n != nil { // fmt.Printf("title: %s\n", n.InnerText()) // } if l := xmlquery.Find(doc, "//maps[@id='9']"); l != nil { t := l[0].Attr fmt.Printf("%v", t[1]) } // for i, n := range xmlquery.Find(doc, "//maps/@id") { // fmt.Printf("#%d %s\n", i, n.InnerText()) // } }