Создайте файл XBRL в Python

Создайте экземпляр XBRL в C#

Aspose.Finance поддерживает создание XBRL документов. Для этого API предоставляет класс XbrlDocument. Конструктор по умолчанию класса XbrlDocument можно использовать для создания нового экземпляра документа XBRL.

Следующий фрагмент кода демонстрирует создание нового экземпляра документа XBRL.

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

Добавить ссылку на схему

Aspose.Finance позволяет добавить ссылку на схему во вновь созданный экземпляр XBRL. Для этого API предоставляет класс SchemaRefCollection.

В следующем фрагменте кода показано добавление ссылки на схему во вновь созданный экземпляр XBRL.

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"))

Добавить контекст

Aspose.Finance позволяет добавить контекст во вновь созданный экземпляр XBRL. Для этого API предоставляет класс Context.

Следующий фрагмент кода демонстрирует добавление контекста во вновь созданный экземпляр XBRL.

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"))

Добавить единицу

Aspose.Finance позволяет добавить контекст во вновь созданный экземпляр XBRL. Для этого API предоставляет класс Unit.

В следующем фрагменте кода показано, как добавить единицу во вновь созданный экземпляр XBRL.

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"))

Добавить элемент

Aspose.Finance позволяет добавлять элементы во вновь созданный экземпляр XBRL. Для этого API предоставляет класс Item.

В следующем фрагменте кода показано, как добавить элемент во вновь созданный экземпляр XBRL.

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"))

Добавить ссылку на сноску

Aspose.Finance позволяет добавить ссылку на сноску во вновь созданный экземпляр XBRL. Для этого API предоставляет класс FootnoteLink.

В следующем фрагменте кода показано, как добавить ссылку на сноску во вновь созданный экземпляр XBRL.

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"))

Добавить ссылку на роль

Aspose.Finance позволяет добавить ссылку на роль во вновь созданный экземпляр XBRL. Для этого API предоставляет класс RoleReference.

В следующем фрагменте кода показано, как добавить ссылку на роль во вновь созданный экземпляр XBRL.

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"))

Добавить ссылку на роль дуги

Aspose.Finance позволяет добавить ссылку на роль дуги во вновь созданный экземпляр XBRL. Для этого API предоставляет класс ArcroleReference.

В следующем фрагменте кода показано, как добавить ссылку на роль дуги во вновь созданный экземпляр XBRL.

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"))