Documentation
¶
Overview ¶
Package ixbrl parses inline-XBRL filings: the fact stream and its contexts (this file's siblings), and — in later phases — the presentation-linkbase projection, layout tables, and free-text sections.
All parsing walks the *html.Node tree produced by golang.org/x/net/html. The HTML5 tokenizer lowercases every element and attribute name, so the XML namespaced names from the source ("xbrli:context", "ix:nonFraction", "contextRef") appear here lowercased ("xbrli:context", "ix:nonfraction", "contextref"). The name constants in this package are written accordingly.
Index ¶
- func ExtractLayoutTable(table *html.Node) *model.Table
- func ParseContexts(doc *html.Node) (map[string]Context, error)
- func ParseRoleTitles(schemaXSD []byte) (map[string]string, error)
- func ProjectTable(role LinkbaseRole, facts []Fact, contexts map[string]Context) *model.Table
- type Context
- type Fact
- type LinkbaseRole
- type RoleConcept
- type Segment
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractLayoutTable ¶
ExtractLayoutTable extracts a narrative HTML table — one not bound to the iXBRL fact stream — into a *Table using the five-phase layout pipeline: header resolution, footnote stripping, number normalisation, row classification, and structured emit. It is the fallback for tables in MD&A, Risk Factors, and exhibits inside an iXBRL filing.
Values are read by sequence rather than by physical column: each data row's leftmost text cell is the label and its remaining meaningful cells are the values, which sidesteps the spacer and currency columns that pervade EDGAR markup. (Headers subdivided by colspan into distinct sub-columns are not expanded; that is a known limitation of the layout fallback.)
func ParseContexts ¶
ParseContexts builds the context map for an iXBRL document by reading every xbrli:context in the ix:header resources. The key is the context ID that facts reference via contextRef.
func ParseRoleTitles ¶
ParseRoleTitles extracts role-URI → title pairs from a filing schema (.xsd). A roleType definition looks like "9952151 - Statement - CONSOLIDATED STATEMENTS OF OPERATIONS"; the title is the segment after the last " - ".
func ProjectTable ¶
ProjectTable projects the fact stream onto the rows and columns of one statement role. Rows are the role's non-structural concepts in presentation order; columns are the primary (consolidated, unsegmented) contexts that carry facts for those concepts, newest period first. Each cell is the fact matching (concept, contextRef), or null when none exists.
Types ¶
type Context ¶
type Context struct {
ID string
Start time.Time
End time.Time
EntityCIK string // raw identifier text, e.g. "0000320193"
Segments []Segment
}
Context is a resolved xbrli:context: the reporting period and entity a fact's contextRef points at. A duration context has distinct Start/End; an instant context has Start == End.
type Fact ¶
type Fact struct {
// Concept is the taxonomy name, e.g. "us-gaap:RevenueFromContractWithCustomerExcludingAssessedTax".
Concept string
// ContextRef is the context ID the value is reported against.
ContextRef string
// UnitRef is the unit ID for numeric facts (e.g. "usd", "shares"); empty for text facts.
UnitRef string
// Numeric distinguishes ix:nonFraction (true) from ix:nonNumeric (false).
Numeric bool
// Raw is the fact's text content as it appeared in the document, before
// decoration stripping or scaling.
Raw string
// Value is the parsed, scaled, signed numeric value. Meaningful only when Numeric is true.
Value float64
// Scale is the power of ten applied to the source digits (scale="6" → ×10^6).
Scale int
// Decimals is the source decimals attribute — informational precision, not magnitude.
Decimals string
// Negative records whether the value was negated (sign="-" or surrounding parentheses).
Negative bool
// Unparsed marks a numeric fact whose content could not be resolved to a
// number — typically an exotic iXBRL transform (spelled-out words, dates)
// on a narrative custom concept. Raw is preserved; Value is 0. Financial
// statement values use the common dot/comma/dash transforms and parse cleanly.
Unparsed bool
// ID is the fact's id attribute (e.g. "f-66"). golang.org/x/net/html exposes
// no line/column, so this is the fact's source locator for debugging.
ID string
}
Fact is one inline-XBRL fact: a numeric value (ix:nonFraction) or a text value (ix:nonNumeric) bound to a concept and a reporting context.
func ExtractFacts ¶
ExtractFacts walks the document and returns every ix:nonFraction and ix:nonNumeric fact. Facts marked xsi:nil are skipped. Facts whose contextRef does not resolve against contexts are skipped — a dangling reference cannot be projected — so a valid filing (every fact's context defined) loses nothing. A numeric fact whose content can't be resolved to a number is kept with Unparsed set rather than aborting extraction of the whole filing.
type LinkbaseRole ¶
type LinkbaseRole struct {
// RoleURI identifies the statement, e.g.
// "http://www.apple.com/role/CONSOLIDATEDSTATEMENTSOFOPERATIONS".
RoleURI string
// Title is the human-readable statement name from the schema's role
// definition (e.g. "CONSOLIDATED STATEMENTS OF OPERATIONS"); when the schema
// is unavailable it is derived from the role URI's final path segment.
Title string
// Concepts is the ordered concept list for the statement.
Concepts []RoleConcept
}
LinkbaseRole is one statement's presentation tree: an ordered, depth-tagged list of concepts with display labels already resolved from the label linkbase. Concepts appear in presentation (depth-first, arc-order) order, which is the row order of the projected table.
func ParseLinkbase ¶
func ParseLinkbase(presentationXML, labelXML []byte, roleTitles map[string]string) ([]LinkbaseRole, error)
ParseLinkbase parses a filing's presentation and label linkbases into one LinkbaseRole per statement. The presentation linkbase supplies concept order and parent-child structure; the label linkbase supplies the display text, resolved against each arc's preferred label role. roleTitles maps a role URI to its schema-defined title and may be nil — a missing title is derived from the role URI.
type RoleConcept ¶
type RoleConcept struct {
// Name is the taxonomy concept in prefix:Local form, e.g. "us-gaap:GrossProfit".
Name string
// Label is the resolved display text for this concept under its preferred
// label role — the filing's own wording ("Net sales", "Total operating
// expenses"), not the generic taxonomy label.
Label string
// PreferredLabel is the label-role URI the presentation arc requested, or ""
// for a root (which has no incoming arc).
PreferredLabel string
// Depth is the nesting level in the presentation tree (root = 0).
Depth int
// HasChildren is true when the concept is a parent in the tree.
HasChildren bool
// Structural marks abstract and dimensional grouping nodes (Abstract, Table,
// Axis, Domain, Member, LineItems) that organise the statement but never
// carry a fact. Projection keeps them for structure but omits them as rows.
Structural bool
}
RoleConcept is one node in a statement's presentation tree.