# xml: 未知属性 "foo"

- **ID:** `go/encoding-xml-unmarshal-unknown-attribute`
- **领域:** go
- **类别:** encoding_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

XML 解码器在输入中遇到了一个未映射到目标结构体任何字段的属性。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| go1.21 | active | — | — |
| go1.22 | active | — | — |

## 解决方案

1. ```
   在结构体中添加具有属性标签的字段：Foo string `xml:"foo,attr"`。
   ```
2. ```
   使用自定义反序列化器或设置 XMLDecoder 的 strict=false（如果使用自定义解析器）。
   ```

## 无效尝试

- **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% 失败率)
- **Ignoring the error and continuing** — The unmarshal returns an error; ignoring it leads to incomplete or nil data. (90% 失败率)
