咖啡伴侶

          呆在上海
          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í)了,留以備用
          主站蜘蛛池模板: 南宫市| 信阳市| 泸水县| 北碚区| 嘉义市| 巫山县| 綦江县| 临猗县| 拉孜县| 丹东市| 四川省| 皋兰县| 杭州市| 奉化市| 安化县| 许昌县| 略阳县| 汨罗市| 涟源市| 句容市| 鄂伦春自治旗| 深圳市| 湘阴县| 石狮市| 石柱| 乌什县| 柯坪县| 洪湖市| 双江| 东方市| 乐亭县| 梅州市| 通渭县| 来宾市| 洛南县| 哈尔滨市| 汉阴县| 永登县| 台东市| 金寨县| 新乡市|