咖啡伴侶

          呆在上海
          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 左岸
          學習了,留以備用
          主站蜘蛛池模板: 陆丰市| 许昌市| 永宁县| 深州市| 乳源| 平陆县| 商洛市| 柳州市| 裕民县| 阿坝| 凌源市| 博野县| 富阳市| 鞍山市| 阳高县| 兴隆县| 阳春市| 永嘉县| 富民县| 南江县| 寿光市| 丰镇市| 西畴县| 西峡县| 兰西县| 荔浦县| 灌云县| 临高县| 凌源市| 石台县| 马龙县| 亚东县| 盐津县| 泽库县| 潞城市| 四川省| 澎湖县| 拜泉县| 阿拉善盟| 肇州县| 布尔津县|