| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 | package mainimport (	"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"`}type DataXML struct {	XMLName  xml.Name       `xml:"DataXML"`	Head      XMLHead       `xml:"Head"`	Record    []XMLRecord    `xml:"Record"`}type XMLHead struct {	SystemCode  string      `xml:"SystemCode"`	MappingID string         `xml:"MappingID"`	Type     string         `xml:"Type"`	FarmCode   string      `xml:"FarmCode"`	DataNum     string `xml:"DataNum"`}type XMLRecord struct {	FeedCode    string	FeedName    string	FarmCode    string	FeedDate    string	Banci       string	BarName     string	GroupTypeCode    string	GroupTypeName    string	CowAmount    string	PCows    string	RecipeCode    string	RecipeName    string	MixBatch    string	BarStartTime    string	BarEndTime    string	BarRecipePlanWeight    string	BarRecipeRealWeight    string	BarFeedPlanWeight    string	BarFeedRealWeight    string	FDate    string	DStatus    string	UserName    string	UserTrueName    string}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)	W := DataXML{}	W.Head = XMLHead{		SystemCode  : "EE",		MappingID : "RR",		Type     : "TT",		FarmCode   : "YY",		DataNum     : "UU",	}	re := XMLRecord{		FeedCode    : "xx",		FeedName    : "cc",		FarmCode   : "vv",		FeedDate   : "jj",	}	re1 := XMLRecord{		FeedCode    : "qq",		FeedName    : "tt",		FarmCode   : "vv",		FeedDate   : "jj",	}	W.Record = append(W.Record,re,re1)	output1, _ := xml.MarshalIndent(W, "  ", "    ")	fmt.Println(string(output1))}
 |