咖啡伴侶

          呆在上海
          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 閱讀(2690) | 評論 (1)編輯 收藏

          主站蜘蛛池模板: 义马市| 东海县| 布尔津县| 清苑县| 涪陵区| 宁陕县| 七台河市| 宁波市| 田林县| 九江县| 桃园县| 福贡县| 广水市| 突泉县| 四川省| 肥西县| 边坝县| 德安县| 青海省| 纳雍县| 黄山市| 上犹县| 湟中县| 玉环县| 望谟县| 永靖县| 抚顺县| 新建县| 蒲江县| 河源市| 渭南市| 江孜县| 通道| 澄城县| 庆城县| 乌鲁木齐县| 邢台县| 波密县| 成都市| 三明市| 克拉玛依市|