Crear archivo XBRL en C#

Crear XBRL Instancia en C#

Aspose.Finance admite la creación de documentos XBRL. Para ello, el API proporciona la clase XbrlDocument. El constructor por defecto delXbrlDocumento La clase 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.

XbrlDocument document = new XbrlDocument();
XbrlInstanceCollection xbrlInstances = document.XbrlInstances;
XbrlInstance xbrlInstance = xbrlInstances[xbrlInstances.Add()];
document.Save(XbrlFilePath + @"output\document1.xbrl");

Agregar referencia de esquema

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

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

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

Agregar contexto

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

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

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

Agregar unidad

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

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

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

Añadir artículo

Aspose.Finance le permite agregar elementos en la instancia XBRL recién creada. Para esto, el API proporciona elArtículo clase.

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

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

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 esto, el API proporciona elNota al pie de páginaclase.

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

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

Agregar referencia de rol

Aspose.Finance le permite agregar una referencia de rol en la instancia XBRL recién creada. Para esto, el API proporciona elReferencia de rolclase.

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

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

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 esto, el API proporciona elArcoleReferenciaclase.

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

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