pub struct InstanceDocument { /* private fields */ }Expand description
Represents a complete XBRL instance document
Implementations§
Source§impl InstanceDocument
impl InstanceDocument
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
Sourcepub fn from_taxonomy(
taxonomy: &TaxonomySet,
namespaces: HashMap<NamespacePrefix, NamespaceUri>,
instant_context: Context,
duration_context: Context,
units: &[Unit],
) -> Self
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
unitRefbased 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.
Sourcepub fn from_file(path: &Path) -> Result<Self>
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.
Sourcepub fn from_reader<R>(reader: R) -> Result<Self>where
R: BufRead,
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.
Sourcepub fn from_xml_reader<R>(reader: Reader<R>) -> Result<Self>where
R: BufRead,
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.
Sourcepub fn validate(&self, taxonomy: &TaxonomySet) -> ValidationResult
pub fn validate(&self, taxonomy: &TaxonomySet) -> ValidationResult
Validate this instance against a taxonomy.
Sourcepub fn view<'a>(&self, taxonomy: &'a TaxonomySet) -> DocumentView<'a>
pub fn view<'a>(&self, taxonomy: &'a TaxonomySet) -> DocumentView<'a>
Convenience wrapper for DocumentView::build using this instance’s item facts.
Sourcepub fn to_file(&self, path: &Path) -> Result<()>
pub fn to_file(&self, path: &Path) -> Result<()>
Serialize this instance to an XML file at the given path.
Sourcepub fn to_writer<W>(&self, writer: W) -> Result<()>where
W: Write,
pub fn to_writer<W>(&self, writer: W) -> Result<()>where
W: Write,
Serialize this instance to an XBRL XML document using a writer.
Sourcepub fn to_xml_writer<W>(&self, writer: &mut Writer<W>) -> Result<()>where
W: Write,
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.
Sourcepub fn add_schema_ref(&mut self, href: String)
pub fn add_schema_ref(&mut self, href: String)
Add a schema reference (xlink:href from a link:schemaRef element)
Sourcepub fn schema_refs(&self) -> &[String]
pub fn schema_refs(&self) -> &[String]
Get all schema references declared in the instance document.
Sourcepub fn add_role_ref(&mut self, role_uri: String)
pub fn add_role_ref(&mut self, role_uri: String)
Add a role reference URI from a roleRef element.
Sourcepub fn role_refs(&self) -> &[String]
pub fn role_refs(&self) -> &[String]
Get all role reference URIs declared in the instance document.
Sourcepub fn add_arcrole_ref(&mut self, arcrole_uri: String)
pub fn add_arcrole_ref(&mut self, arcrole_uri: String)
Add an arcrole reference URI from an arcroleRef element.
Sourcepub fn arcrole_refs(&self) -> &[String]
pub fn arcrole_refs(&self) -> &[String]
Get all arcrole reference URIs declared in the instance document.
Sourcepub fn schema_ref_paths(&self) -> Vec<&str>
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.
Sourcepub fn add_context(&mut self, context: Context)
pub fn add_context(&mut self, context: Context)
Add a context to the instance
Sourcepub fn get_context(&self, id: &str) -> Option<&Context>
pub fn get_context(&self, id: &str) -> Option<&Context>
Get a context by ID
Sourcepub fn item_facts(&self) -> Vec<&ItemFact>
pub fn item_facts(&self) -> Vec<&ItemFact>
Get all item facts in depth-first order.
Sourcepub fn item_fact_count(&self) -> usize
pub fn item_fact_count(&self) -> usize
Number of item facts in the instance (including nested tuple descendants).
Sourcepub fn set_fact_value(&mut self, index: usize, value: String)
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.
Sourcepub fn add_namespace(&mut self, prefix: NamespacePrefix, uri: NamespaceUri)
pub fn add_namespace(&mut self, prefix: NamespacePrefix, uri: NamespaceUri)
Add a namespace prefix mapping
Sourcepub fn get_namespace(&self, prefix: &str) -> Option<&str>
pub fn get_namespace(&self, prefix: &str) -> Option<&str>
Get namespace URI for a prefix
Sourcepub fn namespaces(&self) -> &HashMap<NamespacePrefix, NamespaceUri>
pub fn namespaces(&self) -> &HashMap<NamespacePrefix, NamespaceUri>
Get all namespace prefix mappings