咖啡伴侶

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

          置頂隨筆

          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)
          }

          posted @ 2013-08-16 15:53 oathleo 閱讀(2695) | 評論 (1)編輯 收藏

          主站蜘蛛池模板: 盐津县| 台中县| 铜鼓县| 罗平县| 精河县| 武清区| 丰原市| 星子县| 安国市| 定远县| 监利县| 雅江县| 尼木县| 恭城| 澄城县| 河北省| 西贡区| 青州市| 遂川县| 平塘县| 筠连县| 林州市| 嘉兴市| 平顺县| 吴旗县| 鹤壁市| 黄骅市| 新化县| 清河县| 烟台市| 孟村| 青田县| 吉木萨尔县| 宾川县| 仙居县| 郑州市| 大英县| 都江堰市| 金湖县| 光泽县| 岳西县|