咖啡伴侶

          呆在上海
          posts - 163, comments - 156, trackbacks - 0, articles - 2

          golang xml 處理之生成 屬性必須大寫

          Posted on 2013-08-16 15:53 oathleo 閱讀(2691) 評論(1)  編輯  收藏 所屬分類: Golang
          xml對應的struct 屬性必須大寫,否則無法實現!
          Code是必須的
          package main

          import (
              "encoding/xml"
              "fmt"
              "os"
          )

          type xmldas struct {
              XMLName  xml.Name       `xml:"das"`
              DataPort string         `xml:"DataPort,attr"`
              Desc     string         `xml:"desc,attr"`
              Src      xmlsource      `xml:"source"`
              Dest     xmldestination `xml:"destination"`
          }

          type xmlsource struct {
              Path  string `xml:"path,attr"`
              Param string `xml:"param,attr"`
          }

          type xmldestination struct {
              Path  string `xml:"path,attr"`
              Param string `xml:"param,attr"`
          }

          func main() {
              v := xmldas{DataPort: "8250", Desc: "123"}
              v.Src = xmlsource{Path: "123", Param: "456"}
              v.Dest = xmldestination{Path: "789", Param: "000"}
              output, err := xml.MarshalIndent(v, "  ", "    ")
              if err != nil {
                  fmt.Printf("error: %v\n", err)
              }
              os.Stdout.Write([]byte(xml.Header))
              os.Stdout.Write(output)
          }

          Feedback

          # re: golang xml 處理之生成 屬性必須大寫  回復  更多評論   

          2013-12-15 00:00 by 左岸
          學習了,留以備用
          主站蜘蛛池模板: 沙坪坝区| 汉阴县| 揭东县| 隆化县| 潍坊市| 温宿县| 永福县| 麻栗坡县| 镇平县| 城口县| 仪征市| 海盐县| 平安县| 靖边县| 襄垣县| 旬阳县| 颍上县| 扶沟县| 湖南省| 绩溪县| 舞钢市| 承德县| 通道| 延津县| 龙川县| 革吉县| 虞城县| 宽城| 志丹县| 三明市| 廊坊市| 双鸭山市| 林西县| 大庆市| 旬邑县| 镇原县| 平果县| 百色市| 奇台县| 乐至县| 固阳县|