XML marshal problem

Hello

bellow is my code. Why in my case xml tage does not work?
also in comment is how to xml should look like

Thank you!

package main

import (
	"encoding/xml"
	"fmt"
	"os"
)

type SmsXML struct {
	XMLName       xml.Name `xml: "Packet"`
	ID            int      `xml: "Header>ID"`
	Content       string   `xml: "Body>Item>Content"`
	PhoneNo       string   `xml: "Body>Item>Phone_no"`
	Content1      string   `xml: "Body>Item>Content"`
	OriginAddress string   `xml: "Body>Item>OriginAddress"`
}

/*
<Packet>
		<Header>
		 <ID>2342353456465</ID>
		 </Header>
		 <Body>
		 <Item>
		 <Content>SMS</Content>
		 <Phone_no>+123123213</Phone_no>
		 <Content>test</Content>
		 <OriginAddress>sender</OriginAddress>
		 </Item>
		 </Body>
		</Packet>
*/

func main() {
	Send()

}
func Send() {
	data := SmsXML{ID: 213, Content: "SMS", PhoneNo: "+12321321331", Content1: "testNumberOne", OriginAddress: "Sender"}

	output, err := xml.Marshal(data)
	if err != nil {
		fmt.Println("xmlError: ", err)
	}

	os.Stdout.Write(output)

}

i figure it out:slight_smile: It was the spece after "xml: " tag in struct.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.