qax-os/excelize · error
unexpected child of attrValBool
Error message
unexpected child of attrValBool
What it means
ErrAttrValBool is returned by the custom boolean XML attribute unmarshaler (attrValBool.UnmarshalXML) when it encounters an XML StartElement where only a simple character-data value was expected. The attrValBool type is meant to parse text like "1"/"0" or "true"/"false" into a bool, so child elements are invalid. It signals malformed XML content inside a spreadsheet document.
Source
Thrown at errors.go:26
// Supports complex components by high compatibility, and provided streaming
// API for generating or reading data from a worksheet with huge amounts of
// data. This library needs Go version 1.25.0 or later.
package excelize
import (
"errors"
"fmt"
"strings"
)
var (
// ErrAddVBAProject defined the error message on add the VBA project in
// the workbook.
ErrAddVBAProject = errors.New("unsupported VBA project")
// ErrAttrValBool defined the error message on marshal and unmarshal
// boolean type XML attribute.
ErrAttrValBool = errors.New("unexpected child of attrValBool")
// ErrCellCharsLength defined the error message for receiving a cell
// characters length that exceeds the limit.
ErrCellCharsLength = fmt.Errorf("cell value must be 0-%d characters", TotalCellChars)
// ErrCellStyles defined the error message on cell styles exceeds the limit.
ErrCellStyles = fmt.Errorf("the cell styles exceeds the %d limit", MaxCellStyles)
// ErrChartTitle defined the error message on both formula and rich text for
// chart title.
ErrChartTitle = errors.New("cannot set both 'Formula' and 'Paragraph' for chart title")
// ErrColumnNumber defined the error message on receive an invalid column
// number.
ErrColumnNumber = fmt.Errorf("the column number must be greater than or equal to %d and less than or equal to %d", MinColumns, MaxColumns)
// ErrColumnWidth defined the error message on receive an invalid column
// width.
ErrColumnWidth = fmt.Errorf("the width of the column must be less than or equal to %d characters", MaxColumnWidth)
// ErrCoordinates defined the error message on invalid coordinates tuples
// length.
ErrCoordinates = errors.New("coordinates length must be 4")
// ErrCustomNumFmt defined the error message on receive the empty customView on GitHub (pinned to f2483381fb)
Solutions
- Fix the source XML so boolean elements contain only text (e.g. <b>true</b>), removing any nested child elements
- Regenerate the file with Excel or a compliant producer instead of hand-editing XML
- Sanitize/normalize the offending XML part before opening with the library
- If you cannot control the file, pre-validate the XML or report the malformed source to its producer
Example fix
// before (XML) <applyFont><b>1</b></applyFont> // after (XML) <applyFont>1</applyFont>
Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-scan the XML part for nested elements inside simple-text nodes: // decoder.Token() returning xml.StartElement where a chardata bool was expected means the file is malformed.
Try / catch
_, err := f.Styles()
if errors.Is(err, excelize.ErrAttrValBool) {
// reject or sanitize the malformed XML source before retrying
} Prevention
- Do not hand-edit xlsx XML parts
- Prefer files produced by Excel or compliant libraries
- Fuzz/sanity-check third-party spreadsheets before decoding
- Keep the library updated; unmarshaler handling may improve
When it happens
Trigger: Unmarshaling XML where an element mapped to attrValBool contains a nested child element (xml.StartElement) instead of plain text; typically when decoding a hand-edited, third-party-generated, or corrupted xlsx part.
Common situations: Opening spreadsheets produced by non-Excel tools that emit nested tags inside boolean attributes; manual XML editing of sheet/styles parts; fuzzed or truncated files fed to f.Styles() or other internal XML decoding paths.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
AI-assisted analysis of qax-os/excelize@f2483381fb (2026-09-02).
Data as JSON: /api/errors/3345e106b79b48b8.
Report an issue: GitHub.