main.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package main
  2. import (
  3. "encoding/xml"
  4. "fmt"
  5. "os"
  6. )
  7. type xmldas struct {
  8. XMLName xml.Name `xml:"das"`
  9. DataPort string `xml:"DataPort,attr"`
  10. Desc string `xml:"desc,attr"`
  11. Src xmlsource `xml:"source"`
  12. Dest xmldestination `xml:"destination"`
  13. }
  14. type xmlsource struct {
  15. Path string `xml:"path,attr"`
  16. Param string `xml:"param,attr"`
  17. }
  18. type xmldestination struct {
  19. Path string `xml:"path,attr"`
  20. Param string `xml:"param,attr"`
  21. }
  22. type DataXML struct {
  23. XMLName xml.Name `xml:"DataXML"`
  24. Head XMLHead `xml:"Head"`
  25. Record []XMLRecord `xml:"Record"`
  26. }
  27. type XMLHead struct {
  28. SystemCode string `xml:"SystemCode"`
  29. MappingID string `xml:"MappingID"`
  30. Type string `xml:"Type"`
  31. FarmCode string `xml:"FarmCode"`
  32. DataNum string `xml:"DataNum"`
  33. }
  34. type XMLRecord struct {
  35. FeedCode string
  36. FeedName string
  37. FarmCode string
  38. FeedDate string
  39. Banci string
  40. BarName string
  41. GroupTypeCode string
  42. GroupTypeName string
  43. CowAmount string
  44. PCows string
  45. RecipeCode string
  46. RecipeName string
  47. MixBatch string
  48. BarStartTime string
  49. BarEndTime string
  50. BarRecipePlanWeight string
  51. BarRecipeRealWeight string
  52. BarFeedPlanWeight string
  53. BarFeedRealWeight string
  54. FDate string
  55. DStatus string
  56. UserName string
  57. UserTrueName string
  58. }
  59. func main() {
  60. v := xmldas{DataPort: "8250", Desc: "123"}
  61. v.Src = xmlsource{Path: "123", Param: "456"}
  62. v.Dest = xmldestination{Path: "789", Param: "000"}
  63. output, err := xml.MarshalIndent(v, " ", " ")
  64. if err != nil {
  65. fmt.Printf("error: %v\n", err)
  66. }
  67. os.Stdout.Write([]byte(xml.Header))
  68. os.Stdout.Write(output)
  69. W := DataXML{}
  70. W.Head = XMLHead{
  71. SystemCode : "EE",
  72. MappingID : "RR",
  73. Type : "TT",
  74. FarmCode : "YY",
  75. DataNum : "UU",
  76. }
  77. re := XMLRecord{
  78. FeedCode : "xx",
  79. FeedName : "cc",
  80. FarmCode : "vv",
  81. FeedDate : "jj",
  82. }
  83. re1 := XMLRecord{
  84. FeedCode : "qq",
  85. FeedName : "tt",
  86. FarmCode : "vv",
  87. FeedDate : "jj",
  88. }
  89. W.Record = append(W.Record,re,re1)
  90. output1, _ := xml.MarshalIndent(W, " ", " ")
  91. fmt.Println(string(output1))
  92. }