咖啡伴侶

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

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

          Posted on 2013-08-16 15:53 oathleo 閱讀(2695) 評論(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 左岸
          學習了,留以備用
          主站蜘蛛池模板: 从化市| 革吉县| 娱乐| 定结县| 玉林市| 正阳县| 昭平县| 盘山县| 渭南市| 嘉峪关市| 泾川县| 建德市| 孟津县| 江津市| 西乌| 承德市| 新营市| 崇礼县| 崇文区| 石泉县| 安化县| 龙岩市| 克东县| 阜阳市| 高邑县| 临潭县| 新宁县| 溧阳市| 温宿县| 天峨县| 云林县| 唐河县| 青海省| 罗城| 蛟河市| 碌曲县| 青河县| 石楼县| 漳州市| 玛多县| 宁武县|