4.xml格式数据输出

最后更新于:2022-04-02 04:53:34

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 ~~~ ~~~ Document

{{.xml}}

~~~ 浏览器访问: 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. Murphy 28 帝都 ~~~
';