Crear archivo XBRL en Python

Crear XBRL Instancia en C#

Aspose.Finance admite la creación de documentos XBRL. Para ello, el API proporciona la clase XbrlDocument. El constructor predeterminado de la clase XbrlDocument se puede usar para crear un nuevo documento de instancia XBRL.

El siguiente fragmento de código demuestra la creación de un nuevo documento de instancia XBRL.

xbrlDoc = XbrlDocument()
xbrlInstances = xbrlDoc.xbrl_instances
xbrlInstance = xbrlInstances[xbrlInstances.add()]
xbrlDoc.save(os.path.join(outputDir, "dochavingItem.xbrl"))

Agregar referencia de esquema

Aspose.Finance le permite agregar una referencia de esquema en la instancia XBRL recién creada. Para ello, el API proporciona la clase SchemaRefCollection.

El siguiente fragmento de código muestra cómo agregar una referencia de esquema a una instancia XBRL recién creada.

xbrlDoc = XbrlDocument()
xbrlInstances = xbrlDoc.xbrl_instances
xbrlInstance = xbrlInstances[xbrlInstances.add()]
schemaRefs = xbrlInstance.schema_refs
schemaRefs.add(os.path.join(sourceDir, "schema.xsd"), "example", "http://example.com/xbrl/taxonomy")
xbrlDoc.save(os.path.join(outputDir, "dochavingItem.xbrl"))

Agregar contexto

Aspose.Finance le permite agregar contexto en la instancia XBRL recién creada. Para ello, el API proporciona la clase Contexto.

El siguiente fragmento de código muestra cómo agregar contexto en una instancia XBRL recién creada.

xbrlDoc = XbrlDocument()
xbrlInstances = xbrlDoc.xbrl_instances
xbrlInstance = xbrlInstances[xbrlInstances.add()]
contextPeriod = ContextPeriod(datetime(2020,1,1), datetime(2020,2,10))
contextEntity = ContextEntity("exampleIdentifierScheme", "exampleIdentifier")
context = Context(contextPeriod, contextEntity)
xbrlInstance.contexts.append(context)
xbrlDoc.save(os.path.join(outputDir, "dochavingItem.xbrl"))

Agregar unidad

Aspose.Finance le permite agregar contexto en la instancia XBRL recién creada. Para ello, el API proporciona la clase Unit.

El siguiente fragmento de código muestra cómo agregar una unidad en una instancia XBRL recién creada.

xbrlDoc = XbrlDocument()
xbrlInstances = xbrlDoc.xbrl_instances
xbrlInstance = xbrlInstances[xbrlInstances.add()]
unit = Unit(UnitType.MEASURE)
unit.measure_qualified_names.append(QualifiedName("USD", "iso4217", "http://www.xbrl.org/2003/iso4217"))
xbrlInstance.units.append(unit)
xbrlDoc.save(os.path.join(outputDir, "dochavingItem.xbrl"))

Añadir artículo

Aspose.Finance le permite agregar elementos en la instancia XBRL recién creada. Para ello, el API proporciona la clase Item.

El siguiente fragmento de código muestra cómo agregar un elemento en una instancia XBRL recién creada.

xbrlDoc = XbrlDocument()
xbrlInstances = xbrlDoc.xbrl_instances
xbrlInstance = xbrlInstances[xbrlInstances.add()]
schemaRefs = xbrlInstance.schema_refs
schemaRefs.add(os.path.join(sourceDir, "schema.xsd"), "example", "http://example.com/xbrl/taxonomy")
schema = schemaRefs[0]
contextPeriod = ContextPeriod(datetime(2020,1,1), datetime(2020,2,10))
contextEntity = ContextEntity("exampleIdentifierScheme", "exampleIdentifier")
context = Context(contextPeriod, contextEntity)
xbrlInstance.contexts.append(context)
unit = Unit(UnitType.MEASURE)
unit.measure_qualified_names.append(QualifiedName("USD", "iso4217", "http://www.xbrl.org/2003/iso4217"))
xbrlInstance.units.append(unit)
fixedAssetsConcept = schema.get_concept_by_name("fixedAssets")
if fixedAssetsConcept is not None:
item = Item(fixedAssetsConcept)
item.context_ref = context
item.unit_ref = unit
item.precision = 4
item.value = "1444"
xbrlInstance.facts.append(item)
xbrlDoc.save(os.path.join(outputDir, "dochavingItem.xbrl"))

Agregar enlace de nota al pie

Aspose.Finance le permite agregar un enlace de nota al pie en la instancia XBRL recién creada. Para ello, el API proporciona la clase FootnoteLink.

El siguiente fragmento de código muestra cómo agregar un enlace de nota al pie en una instancia XBRL recién creada.

xbrlDoc = XbrlDocument()
xbrlInstances = xbrlDoc.xbrl_instances
xbrlInstance = xbrlInstances[xbrlInstances.add()]
schemaRefs = xbrlInstance.schema_refs
schemaRefs.add(os.path.join(sourceDir, "schema.xsd"), "example", "http://example.com/xbrl/taxonomy")
schema = schemaRefs[0]
contextPeriod = ContextPeriod(datetime(2020,1,1), datetime(2020,2,10))
contextEntity = ContextEntity("exampleIdentifierScheme", "exampleIdentifier")
context = Context(contextPeriod, contextEntity)
xbrlInstance.contexts.append(context)
footnoteLink = FootnoteLink()
footnote = Footnote("footnote1")
footnote.text = "Including the effects of the merger."
loc = Loc("#cd1", "fact1")
footnoteArc = FootnoteArc(loc.label, footnote.label)
footnoteLink.footnotes.append(footnote)
footnoteLink.locators.append(loc)
footnoteLink.footnote_arcs.append(footnoteArc)
xbrlInstance.footnote_links.append(footnoteLink)
xbrlDoc.save(os.path.join(outputDir, "xbrl_sample_with_footnotelink.xbrl"))

Agregar referencia de rol

Aspose.Finance le permite agregar una referencia de rol en la instancia XBRL recién creada. Para ello, el API proporciona la clase RoleReference.

El siguiente fragmento de código muestra cómo agregar una referencia de rol en una instancia XBRL recién creada.

xbrlDoc = XbrlDocument()
xbrlInstances = xbrlDoc.xbrl_instances
xbrlInstance = xbrlInstances[xbrlInstances.add()]
schemaRefs = xbrlInstance.schema_refs
schemaRefs.add(os.path.join(sourceDir, "schema.xsd"), "example", "http://example.com/xbrl/taxonomy")
schema = schemaRefs[0]
roleType = schema.get_role_type_by_uri("http://abc.com/role/link1")
if roleType is not None:
roleReference = RoleReference(roleType)
xbrlInstance.role_references.append(roleReference)
xbrlDoc.save(os.path.join(outputDir, "xbrl_sample_with_roletype.xbrl"))

Agregar referencia de rol de arco

Aspose.Finance le permite agregar una referencia de rol de arco en la instancia XBRL recién creada. Para ello, el API proporciona la clase ArcoleReference.

El siguiente fragmento de código demuestra cómo agregar una referencia de función de arco en una instancia XBRL recién creada.

xbrlDoc = XbrlDocument()
xbrlInstances = xbrlDoc.xbrl_instances
xbrlInstance = xbrlInstances[xbrlInstances.add()]
schemaRefs = xbrlInstance.schema_refs
schemaRefs.add(os.path.join(sourceDir, "schema.xsd"), "example", "http://example.com/xbrl/taxonomy")
schema = schemaRefs[0]
arcroleType = schema.get_arcrole_type_by_uri("http://abc.com/arcrole/footnote-test")
if arcroleType is not None:
arcroleReference = ArcroleReference(arcroleType)
xbrlInstance.arcrole_references.append(arcroleReference)
xbrlDoc.save(os.path.join(outputDir, "xbrl_sample_with_arcroletype.xbrl"))