xml格式数据输出 通过把要输出的数据放到Data["xml"]中,然后调用ServeXML()进行渲染,就可以把数据进行XML序列化输出。 ~~~ |-- admin | |--controllers | `-- user.go ~~~ ~~~ package admin import ( "github.com/astaxie/beego" ) type UserController struct { beego.Controller } type stu struct { Name string Age int Addr string } func (this *UserController) Index() { user := &stu{"Murphy", 28, "帝都"} this.Data["xml"] = user this.ServeXML() this.TplName = "admin/user/index.html" } ~~~ ~~~ |-- views | |--admin | |--user | `-- index.html ~~~ ~~~ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <h3>{{.xml}}</h3> </body> </html> ~~~ 浏览器访问: http://127.0.0.1:8080/admin/user/index 浏览器输出: ~~~ This XML file does not appear to have any style information associated with it. The document tree is shown below. <stu> <Name>Murphy</Name> <Age>28</Age> <Addr>帝都</Addr> </stu> ~~~