Skip to main content

InstanceDocument

Struct InstanceDocument 

Source
pub struct InstanceDocument { /* private fields */ }
Expand description

Represents a complete XBRL instance document

Implementations§

Source§

impl InstanceDocument

Source

pub fn new( schema_refs: Vec<String>, contexts: HashMap<ContextId, Context>, units: HashMap<UnitId, Unit>, facts: Vec<Fact>, namespaces: HashMap<NamespacePrefix, NamespaceUri>, footnote_links: Vec<FootnoteLink>, ) -> Self

Source

pub fn from_taxonomy( taxonomy: &TaxonomySet, namespaces: HashMap<NamespacePrefix, NamespaceUri>, instant_context: Context, duration_context: Context, units: &[Unit], ) -> Self

Create a new instance pre-wired to a known taxonomy.

  • Registers all schema refs and role refs from the taxonomy
  • Adds both contexts and all provided units
  • Pre-populates nil facts for concepts in the presentation linkbase, preserving tuple nesting derived directly from the presentation tree
  • Assigns each fact the correct unitRef based on its XSD type: monetary → first currency unit, shares → first shares unit, other numeric → first pure unit, non-numeric → no unitRef

Build the DocumentView once after this call, then fill values in-place via [set_fact_value] without rebuilding the view.

Source

pub fn from_file(path: &Path) -> Result<Self>

Parse an XBRL instance document from the file at the given path.

Automatically extracts the <xbrli:xbrl> element if the input contains a wrapper around it.

Source

pub fn from_reader<R>(reader: R) -> Result<Self>
where R: BufRead,

Parse an XBRL instance document from the reader.

Automatically extracts the <xbrli:xbrl> element if the input contains a wrapper around it.

Source

pub fn from_xml_reader<R>(reader: Reader<R>) -> Result<Self>
where R: BufRead,

Parse an XBRL instance document from the XML reader.

Automatically extracts the <xbrli:xbrl> element if the input contains a wrapper around it.

Source

pub fn validate(&self, taxonomy: &TaxonomySet) -> ValidationResult

Validate this instance against a taxonomy.

Source

pub fn view<'a>(&self, taxonomy: &'a TaxonomySet) -> DocumentView<'a>

Convenience wrapper for DocumentView::build using this instance’s item facts.

Source

pub fn to_file(&self, path: &Path) -> Result<()>

Serialize this instance to an XML file at the given path.

Source

pub fn to_writer<W>(&self, writer: W) -> Result<()>
where W: Write,

Serialize this instance to an XBRL XML document using a writer.

Source

pub fn to_xml_writer<W>(&self, writer: &mut Writer<W>) -> Result<()>
where W: Write,

Serialize this instance to an XBRL XML document using an XML writer.

Source

pub fn add_schema_ref(&mut self, href: String)

Add a schema reference (xlink:href from a link:schemaRef element)

Source

pub fn schema_refs(&self) -> &[String]

Get all schema references declared in the instance document.

Source

pub fn add_role_ref(&mut self, role_uri: String)

Add a role reference URI from a roleRef element.

Source

pub fn role_refs(&self) -> &[String]

Get all role reference URIs declared in the instance document.

Source

pub fn add_arcrole_ref(&mut self, arcrole_uri: String)

Add an arcrole reference URI from an arcroleRef element.

Source

pub fn arcrole_refs(&self) -> &[String]

Get all arcrole reference URIs declared in the instance document.

Source

pub fn schema_ref_paths(&self) -> Vec<&str>

Extract relative path suffixes from schema reference URLs.

Strips the URL scheme, host, and leading /taxonomies/ segment to produce paths suitable for joining with a local taxonomy directory.

For example: http://www.xbrl.de/taxonomies/de-gcd-2020-04-01/de-gcd-2020-04-01-shell.xsd becomes de-gcd-2020-04-01/de-gcd-2020-04-01-shell.xsd.

Source

pub fn add_context(&mut self, context: Context)

Add a context to the instance

Source

pub fn get_context(&self, id: &str) -> Option<&Context>

Get a context by ID

Source

pub fn add_unit(&mut self, unit: Unit)

Add a unit to the instance

Source

pub fn get_unit(&self, id: &str) -> Option<&Unit>

Get a unit by ID

Source

pub fn add_fact(&mut self, fact: Fact)

Add a fact to the instance

Source

pub fn facts(&self) -> &[Fact]

Get all top-level facts.

Source

pub fn facts_mut(&mut self) -> &mut [Fact]

Get all top-level facts mutably.

Source

pub fn item_facts(&self) -> Vec<&ItemFact>

Get all item facts in depth-first order.

Source

pub fn item_fact_count(&self) -> usize

Number of item facts in the instance (including nested tuple descendants).

Source

pub fn set_fact_value(&mut self, index: usize, value: String)

Set the value of a fact by its index (from DocumentView fact_indices). Clears nil status.

§Panics

Panics if index is out of bounds.

Source

pub fn add_namespace(&mut self, prefix: NamespacePrefix, uri: NamespaceUri)

Add a namespace prefix mapping

Source

pub fn get_namespace(&self, prefix: &str) -> Option<&str>

Get namespace URI for a prefix

Source

pub fn namespaces(&self) -> &HashMap<NamespacePrefix, NamespaceUri>

Get all namespace prefix mappings

Source

pub fn contexts(&self) -> &HashMap<ContextId, Context>

Get all contexts

Source

pub fn units(&self) -> &HashMap<UnitId, Unit>

Get all units

Trait Implementations§

Source§

impl Debug for InstanceDocument

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for InstanceDocument

Source§

fn default() -> InstanceDocument

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.