InformationUser:[{
"informationUser.availabiltyStartDate:"09/10/2019 23:56:19",
"informationUSer.avaialblilityEndDate:"28/11/2019 21:19:16",
}]
Asked
Active
Viewed 456 times
-3

Jonathan Hall
- 75,165
- 16
- 143
- 189

GeekyBoy
- 15
- 6
-
1Please take a look at package encoding/xml. – Volker Dec 02 '19 at 09:59
-
Please share the link . – GeekyBoy Dec 02 '19 at 10:07
-
1What have you tried? Include your code. What problems did you encounter? – Jonathan Hall Dec 02 '19 at 10:22
-
1You have this link for converting map to xml: https://stackoverflow.com/questions/30928770/marshall-map-to-xml-in-go – edkeveked Dec 02 '19 at 10:23
-
2This is a package if the stdlib. You should not need link for that. – Volker Dec 02 '19 at 10:27
-
@volker the stdlib xml encoder does not support encoding maps. Please read the question linked by edkeveked. – chmike Dec 02 '19 at 10:30
1 Answers
0
Have a look on docs: https://golang.org/pkg/encoding/xml/
And here you have a little example:
package tests
import (
"encoding/xml"
"fmt"
"testing"
)
type Person struct {
FirstName string `xml:"first_name"`
LastName string `xml:"last_name"`
Age int `xml:"age,attr"`
}
func TestXmlToString(t *testing.T) {
person := Person{
FirstName: "John",
LastName: "Rambo",
Age: 66,
}
data, err := xml.Marshal(person)
if err != nil {
t.Fatal(err)
}
fmt.Printf("Xml: %s\n", data)
}
func TestStringToXml(t *testing.T) {
input := `<Person age="66"><first_name>John</first_name><last_name>Rambo</last_name></Person>`
person := Person{}
err := xml.Unmarshal([]byte(input), &person)
if err != nil {
t.Fatal(err)
}
fmt.Printf("Data: %#v\n", person)
}

m-szalik
- 3,546
- 1
- 21
- 28
-
If Map Data is given in file, then how should i fetch data from file & generate the xml file. – GeekyBoy Dec 02 '19 at 16:32