咖啡伴侶

          呆在上海
          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)編輯 收藏

          主站蜘蛛池模板: 边坝县| 海丰县| 丰宁| 芜湖市| 农安县| 宁河县| 盐津县| 林西县| 沭阳县| 嵩明县| 澎湖县| 南汇区| 常熟市| 漳平市| 荆州市| 中牟县| 咸宁市| 高密市| 平武县| 云霄县| 调兵山市| 青冈县| 如皋市| 财经| 夏邑县| 四平市| 永胜县| 来凤县| 于田县| 兴宁市| 宁河县| 湖口县| 青神县| 武强县| 元江| 奈曼旗| 榆社县| 阳高县| 达拉特旗| 永胜县| 永仁县|