咖啡伴侶

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

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

          Posted on 2013-08-16 15:53 oathleo 閱讀(2695) 評(píng)論(1)  編輯  收藏 所屬分類: Golang
          xml對(duì)應(yīng)的struct 屬性必須大寫,否則無法實(shí)現(xiàn)!
          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 處理之生成 屬性必須大寫  回復(fù)  更多評(píng)論   

          2013-12-15 00:00 by 左岸
          學(xué)習(xí)了,留以備用
          主站蜘蛛池模板: 庆云县| 通化市| 大名县| 万源市| 合江县| 闽清县| 澄迈县| 藁城市| 德惠市| 黑龙江省| 安塞县| 丰原市| 察雅县| 荔波县| 聂拉木县| 千阳县| 浦县| 东阳市| 房产| 邵阳市| 吴江市| 裕民县| 民权县| 嘉定区| 华坪县| 界首市| 平安县| 山东省| 福泉市| 托克托县| 华宁县| 卢龙县| 五莲县| 崇左市| 延吉市| 河南省| 鹤峰县| 察雅县| 双柏县| 宕昌县| 西城区|