---
source: https://iinventedlight.com/library/notes/go-encoding-xml.md
title: "Go encoding/xml: a simple XML 1.0 parser"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (Go); BSD-3-Clause (Go); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Go, encoding/xml package reference; Go, encoding/xml source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: go-encoding-xml"
tags: [go, encoding, xml, marshal, parser]
client: Librarian
sources:
  - id: S1
    title: "encoding/xml package reference"
    publisher: Go
    url: https://pkg.go.dev/encoding/xml
    accessed: 2026-11-23
    license: "BSD-3-Clause"
  - id: S2
    title: "encoding/xml source"
    publisher: Go
    url: https://go.dev/src/encoding/xml/xml.go
    accessed: 2026-11-23
    license: "BSD-3-Clause"
---
# Go encoding/xml: a simple XML 1.0 parser
**Answer:** Package xml implements a simple XML 1.0 parser that understands XML name spaces. Marshal returns the XML encoding of v. Unmarshal parses XML-encoded data and stores the result in v.

## Marshaling and tokens

The package implements a simple XML 1.0 parser that understands XML name spaces.

Marshal returns the XML encoding of v. MarshalIndent is like Marshal but applies Indent to format the output.

Unmarshal parses XML-encoded data and stores the result in v.

A Decoder reads and decodes XML tokens. An Encoder writes XML tokens.

## The source comment

The source comment describes a simple XML 1.0 parser that understands XML name spaces.

References include the annotated XML spec and XML name spaces.

A SyntaxError represents a syntax error in the XML input stream.

When Token encounters an unrecognized name space prefix, it uses that prefix as the Space rather than report an error.

## See also

- [go-encoding-json](https://iinventedlight.com/library/notes/go-encoding-json/)
- [go-encoding-csv](https://iinventedlight.com/library/notes/go-encoding-csv/)
- [go-encoding-hex](https://iinventedlight.com/library/notes/go-encoding-hex/)

## Claims

- id: C1
  claim: The package implements a simple XML 1.0 parser that understands name spaces.
  source: S1
  evidence: "a simple XML 1.0 parser that understands XML name spaces"

- id: C2
  claim: Marshal encodes a value to XML bytes.
  source: S1
  evidence: "func Marshal(v any) ([]byte, error)"

- id: C3
  claim: The source comment describes a simple XML 1.0 parser.
  source: S2
  evidence: "Package xml implements a simple XML 1.0 parser that"

- id: C4
  claim: The parser understands XML name spaces.
  source: S2
  evidence: "understands XML name spaces."

## Sources

- [S1] encoding/xml package reference. Go. https://pkg.go.dev/encoding/xml . License: BSD-3-Clause. Accessed 2026-11-23.

- [S2] encoding/xml source. Go. https://go.dev/src/encoding/xml/xml.go . License: BSD-3-Clause. Accessed 2026-11-23.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go, encoding/xml package reference; Go, encoding/xml source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
