xbrl

package module
v0.0.0-...-83b5e8d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 5 Imported by: 0

README

xbrl

A simple parser for XBRL files.

Usage

func main() {
	file, err := os.Open("msft.xml")
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()

	var xbrl xbrl.XBRL
	if err := xml.NewDecoder(file).Decode(&xbrl); err != nil {
		log.Fatal(err)
	}

	fmt.Println("Facts:", len(xbrl.Facts))
}

Example fact from parsed XBRL

{
  "context": {
    "entity": "0000789019",
    "segments": [
      {
        "dimension": "DerivativeInstrumentRisk",
        "member": "InterestRateContract"
      },
      {
        "dimension": "DerivativeInstrumentsGainLossByHedgingRelationship",
        "member": "FairValueHedging"
      },
      {
        "dimension": "IncomeStatementLocation",
        "member": "NonoperatingIncomeExpense"
      }
    ],
    "period": {
      "startDate": "2023-10-01",
      "endDate": "2023-12-31"
    }
  },
  "concept": "ChangeInUnrealizedGainLossOnHedgedItemInFairValueHedge1",
  "value": -34000000,
  "decimals": "-6",
  "unit": "USD"
},

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	Entity   string    `json:"entity"`
	Segments []Segment `json:"segments"`
	Period   Period    `json:"period"`
}

Context represents the context of a fact in the XBRL data.

func (Context) String

func (c Context) String() string

String returns a string representation of the context.

type Fact

type Fact struct {
	Context  Context `json:"context"`
	Concept  string  `json:"concept"`
	Value    any     `json:"value"`
	Decimals string  `json:"decimals,omitempty"`
	Unit     string  `json:"unit,omitempty"`
}

Fact represents a single fact in the XBRL data.

func (Fact) String

func (f Fact) String() string

String returns a string representation of the fact.

type Period

type Period struct {
	Instant   string `json:"instant,omitempty"`
	StartDate string `json:"startDate,omitempty"`
	EndDate   string `json:"endDate,omitempty"`
}

Period represents the period of a fact in the XBRL data.

func (Period) String

func (p Period) String() string

String returns a string representation of the period.

type Segment

type Segment struct {
	Dimension string `json:"dimension"`
	Member    string `json:"member"`
}

Segment represents a segment in the context of a fact in the XBRL data.

func (Segment) String

func (s Segment) String() string

String returns a string representation of the segment.

type XBRL

type XBRL struct {
	Facts []Fact `json:"facts"`
}

XBRL represents the parsed XBRL data.

func (*XBRL) NumericFacts

func (x *XBRL) NumericFacts() []Fact

NumericFacts returns only the facts that have numeric values (integers or floats).

func (*XBRL) String

func (x *XBRL) String() string

String returns a string representation of the XBRL data.

func (*XBRL) UnmarshalXML

func (x *XBRL) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML decodes the XML data into the XBRL struct.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL