# xml: unknown attribute "foo"

- **ID:** `go/encoding-xml-unmarshal-unknown-attribute`
- **Domain:** go
- **Category:** encoding_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

The XML decoder encountered an attribute in the input that does not map to any field in the target struct.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| go1.21 | active | — | — |
| go1.22 | active | — | — |

## Workarounds

1. **Add a field with the attribute tag: Foo string `xml:"foo,attr"` in the struct.** (95% success)
   ```
   Add a field with the attribute tag: Foo string `xml:"foo,attr"` in the struct.
   ```
2. **Use a custom unmarshaler or XMLDecoder with strict=false if using custom parser.** (70% success)
   ```
   Use a custom unmarshaler or XMLDecoder with strict=false if using custom parser.
   ```

## Dead Ends

- **Adding a field with xml:"foo,attr" but with wrong type** — If the field type doesn't match the attribute value (e.g., int vs string), it still fails with type error. (55% fail)
- **Ignoring the error and continuing** — The unmarshal returns an error; ignoring it leads to incomplete or nil data. (90% fail)
