Crea il file XBRL in C#
Crea istanza XBRL in C#
Aspose.Finance supporta la creazione di documenti XBRL. Per questo, lo API fornisce la classe XbrlDocument. Il costruttore predefinito diXbrlDocumento class può essere utilizzata per creare un nuovo documento di istanza XBRL.
Il seguente frammento di codice illustra la creazione di un nuovo documento di istanza XBRL.
XbrlDocument document = new XbrlDocument(); | |
XbrlInstanceCollection xbrlInstances = document.XbrlInstances; | |
XbrlInstance xbrlInstance = xbrlInstances[xbrlInstances.Add()]; | |
document.Save(XbrlFilePath + @"output\document1.xbrl"); |
Aggiungi riferimento allo schema
Aspose.Finance consente di aggiungere un riferimento allo schema nell’istanza XBRL appena creata. Per questo, lo API fornisce ilSchemaRefCollection classe.
Il frammento di codice seguente illustra l’aggiunta di un riferimento allo schema a un’istanza XBRL appena creata.
XbrlDocument document = new XbrlDocument(); | |
XbrlInstanceCollection xbrlInstances = document.XbrlInstances; | |
XbrlInstance xbrlInstance = xbrlInstances[xbrlInstances.Add()]; | |
SchemaRefCollection schemaRefs = xbrlInstance.SchemaRefs; | |
schemaRefs.Add(XbrlFilePath + @"schema.xsd", "example", "http://example.com/xbrl/taxonomy"); | |
document.Save(XbrlFilePath + @"output\document2.xbrl"); |
Aggiungi contesto
Aspose.Finance consente di aggiungere contesto nell’istanza XBRL appena creata. Per questo, lo API fornisce ilContestoclasse.
Il frammento di codice seguente illustra l’aggiunta di contesto in un’istanza XBRL appena creata.
XbrlDocument document = new XbrlDocument(); | |
XbrlInstanceCollection xbrlInstances = document.XbrlInstances; | |
XbrlInstance xbrlInstance = xbrlInstances[xbrlInstances.Add()]; | |
ContextPeriod contextPeriod = new ContextPeriod(DateTime.Parse("2020-01-01"), DateTime.Parse("2020-02-10")); | |
ContextEntity contextEntity = new ContextEntity("exampleIdentifierScheme", "exampleIdentifier"); | |
Context context = new Context(contextPeriod, contextEntity); | |
xbrlInstance.Contexts.Add(context); | |
document.Save(XbrlFilePath + @"output\document3.xbrl"); |
Aggiungi unità
Aspose.Finance consente di aggiungere contesto nell’istanza XBRL appena creata. Per questo, lo API fornisce ilUnità classe.
Il frammento di codice seguente mostra come aggiungere un’unità in un’istanza XBRL appena creata.
XbrlDocument document = new XbrlDocument(); | |
XbrlInstanceCollection xbrlInstances = document.XbrlInstances; | |
XbrlInstance xbrlInstance = xbrlInstances[xbrlInstances.Add()]; | |
Unit unit = new Unit(UnitType.Measure); | |
unit.MeasureQualifiedNames.Add(new QualifiedName("USD", "iso4217", "http://www.xbrl.org/2003/iso4217")); | |
xbrlInstance.Units.Add(unit); | |
document.Save(XbrlFilePath + @"output\document4.xbrl"); |
Aggiungi articolo
Aspose.Finance consente di aggiungere elementi nell’istanza XBRL appena creata. Per questo, lo API fornisce ilElemento classe.
Il frammento di codice seguente mostra come aggiungere un elemento in un’istanza XBRL appena creata.
XbrlDocument document = new XbrlDocument(); | |
XbrlInstanceCollection xbrlInstances = document.XbrlInstances; | |
XbrlInstance xbrlInstance = xbrlInstances[xbrlInstances.Add()]; | |
SchemaRefCollection schemaRefs = xbrlInstance.SchemaRefs; | |
schemaRefs.Add(XbrlFilePath + @"schema.xsd", "example", "http://example.com/xbrl/taxonomy"); | |
SchemaRef schema = schemaRefs[0]; | |
ContextPeriod contextPeriod = new ContextPeriod(DateTime.Parse("2020-01-01"), DateTime.Parse("2020-02-10")); | |
ContextEntity contextEntity = new ContextEntity("exampleIdentifierScheme", "exampleIdentifier"); | |
Context context = new Context(contextPeriod, contextEntity); | |
xbrlInstance.Contexts.Add(context); | |
Unit unit = new Unit(UnitType.Measure); | |
unit.MeasureQualifiedNames.Add(new QualifiedName("USD", "iso4217", "http://www.xbrl.org/2003/iso4217")); | |
xbrlInstance.Units.Add(unit); | |
Concept fixedAssetsConcept = schema.GetConceptByName("fixedAssets"); | |
if (fixedAssetsConcept != null) | |
{ | |
Item item = new Item(fixedAssetsConcept); | |
item.ContextRef = context; | |
item.UnitRef = unit; | |
item.Precision = 4; | |
item.Value = "1444"; | |
xbrlInstance.Facts.Add(item); | |
} | |
document.Save(XbrlFilePath + @"output\document5.xbrl"); |
Aggiungi il collegamento alla nota a piè di pagina
Aspose.Finance consente di aggiungere un collegamento a una nota a piè di pagina nell’istanza XBRL appena creata. Per questo, lo API fornisce ilNota a piè di pagina Linkclasse.
Il seguente frammento di codice mostra come aggiungere un collegamento a una nota a piè di pagina in un’istanza XBRL appena creata.
XbrlDocument document = new XbrlDocument(); | |
XbrlInstanceCollection xbrlInstances = document.XbrlInstances; | |
XbrlInstance xbrlInstance = xbrlInstances[xbrlInstances.Add()]; | |
SchemaRefCollection schemaRefs = xbrlInstance.SchemaRefs; | |
schemaRefs.Add(XbrlFilePath + @"schema.xsd", "example", "http://example.com/xbrl/taxonomy"); | |
SchemaRef schema = schemaRefs[0]; | |
ContextPeriod contextPeriod = new ContextPeriod(DateTime.Parse("2020-01-01"), DateTime.Parse("2020-02-10")); | |
ContextEntity contextEntity = new ContextEntity("exampleIdentifierScheme", "exampleIdentifier"); | |
Context context = new Context(contextPeriod, contextEntity); | |
context.Id = "cd1"; | |
xbrlInstance.Contexts.Add(context); | |
FootnoteLink footnoteLink = new FootnoteLink(); | |
Footnote footnote = new Footnote("footnote1"); | |
footnote.Text = "Including the effects of the merger."; | |
Loc loc = new Loc("#cd1", "fact1"); | |
FootnoteArc footnoteArc = new FootnoteArc(loc.Label, footnote.Label); | |
footnoteLink.Footnotes.Add(footnote); | |
footnoteLink.Locators.Add(loc); | |
footnoteLink.FootnoteArcs.Add(footnoteArc); | |
xbrlInstance.FootnoteLinks.Add(footnoteLink); | |
document.Save(XbrlFilePath + @"output\document6.xbrl"); |
Aggiungi riferimento al ruolo
Aspose.Finance consente di aggiungere un riferimento al ruolo nell’istanza XBRL appena creata. Per questo, lo API fornisce ilRiferimento al ruoloclasse.
Il frammento di codice seguente mostra come aggiungere un riferimento al ruolo in un’istanza XBRL appena creata.
XbrlDocument document = new XbrlDocument(); | |
XbrlInstanceCollection xbrlInstances = document.XbrlInstances; | |
XbrlInstance xbrlInstance = xbrlInstances[xbrlInstances.Add()]; | |
SchemaRefCollection schemaRefs = xbrlInstance.SchemaRefs; | |
schemaRefs.Add(XbrlFilePath + @"schema.xsd", "example", "http://example.com/xbrl/taxonomy"); | |
SchemaRef schema = schemaRefs[0]; | |
RoleType roleType = schema.GetRoleTypeByURI("http://abc.com/role/link1"); | |
if (roleType != null) | |
{ | |
RoleReference roleReference = new RoleReference(roleType); | |
xbrlInstance.RoleReferences.Add(roleReference); | |
} | |
document.Save(XbrlFilePath + @"output\document7.xbrl"); |
Aggiungi riferimento al ruolo dell’arco
Aspose.Finance consente di aggiungere un riferimento al ruolo dell’arco nell’istanza XBRL appena creata. Per questo, lo API fornisce ilArcrolReferenceclasse.
Il seguente frammento di codice mostra come aggiungere un riferimento al ruolo dell’arco in un’istanza XBRL appena creata.
XbrlDocument document = new XbrlDocument(); | |
XbrlInstanceCollection xbrlInstances = document.XbrlInstances; | |
XbrlInstance xbrlInstance = xbrlInstances[xbrlInstances.Add()]; | |
SchemaRefCollection schemaRefs = xbrlInstance.SchemaRefs; | |
schemaRefs.Add(XbrlFilePath + @"schema.xsd", "example", "http://example.com/xbrl/taxonomy"); | |
SchemaRef schema = schemaRefs[0]; | |
ArcroleType arcroleType = schema.GetArcroleTypeByURI("http://abc.com/arcrole/footnote-test"); | |
if (arcroleType != null) | |
{ | |
ArcroleReference arcroleReference = new ArcroleReference(arcroleType); | |
xbrlInstance.ArcroleReferences.Add(arcroleReference); | |
} | |
document.Save(XbrlFilePath + @"output\document8.xbrl"); |