package main import ( "encoding/xml" "fmt" "strings" ) func main() { xmlString := "Go Programming " decoder := xml.NewDecoder(strings.NewReader(xmlString)) _, err := decoder.Token() if err != nil { fmt.Println("Error decoding token: ", err) } var title string err = decoder.DecodeElement(&title, nil) if err != nil { fmt.Println("Error decoding element: ", err) } fmt.Println(title) }
Go Programming
package main import ( "encoding/xml" "fmt" "strings" ) type Book struct { Title string `xml:"title"` Author string `xml:"author"` } func main() { xmlString := "" decoder := xml.NewDecoder(strings.NewReader(xmlString)) _, err := decoder.Token() if err != nil { fmt.Println("Error decoding token: ", err) } var book Book err = decoder.DecodeElement(&book, nil) if err != nil { fmt.Println("Error decoding element: ", err) } fmt.Println(book.Title) fmt.Println(book.Author) } Go Programming John Doe
Go Programming John Doe