Standard library / encoding/xml

encoding/xml.SyntaxError

Error with message and source line. Use errors.As to distinguish malformed XML from I/O failure. Expected stdout: 'true 1\n'.

Formal Syntax & Structure

go syntaxgo
type SyntaxError struct {  Msg  string  Line int}

Working Example

Example Snippetgo
package main
import (  "encoding/xml"  "errors"  "fmt")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  var s string  e := xml.Unmarshal([]byte("<a>"), &s)  var se *xml.SyntaxError  fmt.Println(errors.As(e, &se), se.Line)}
Go Reference