Standard library / encoding/xml
encoding/xml.SyntaxError.Error()
Returns a diagnostic for malformed XML, including the line number. Expected stdout: 'true\ntrue\n'.
Formal Syntax & Structure
go syntaxgo
func (e *SyntaxError) Error() stringReturn Value
string
Text representation.
Working Example
Example Snippetgo
package main
import ( "encoding/xml" "errors" "fmt" "strings")
func must(e error) { if e != nil { panic(e) }}
func main() { var v any e := xml.Unmarshal([]byte("<a>"), &v) var se *xml.SyntaxError fmt.Println(errors.As(e, &se)) fmt.Println(strings.Contains(se.Error(), "XML syntax error"))}