在 C# 中创建 XBRL 文件

在 C# 中创建 XBRL 实例

Aspose.Finance支持创建XBRL文档。为此,API 提供了 XbrlDocument 类。的默认构造函数Xbrl文档类可用于创建新的 XBRL 实例文档。

以下代码片段演示了如何创建一个新的 XBRL 实例文档。

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

添加架构引用

Aspose.Finance 允许您在新创建的 XBRL 实例中添加模式引用。为此,API 提供了模式引用集合班级。

以下代码片段演示了将架构引用添加到新创建的 XBRL 实例。

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

添加上下文

Aspose.Finance 允许您在新创建的 XBRL 实例中添加上下文。为此,API 提供了语境班级。

以下代码片段演示了在新创建的 XBRL 实例中添加上下文。

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

添加单位

Aspose.Finance 允许您在新创建的 XBRL 实例中添加上下文。为此,API 提供了单元班级。

以下代码片段演示了如何在新创建的 XBRL 实例中添加一个单元。

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

添加项目

Aspose.Finance 允许您在新创建的 XBRL 实例中添加项目。为此,API 提供了物品班级。

以下代码片段演示了如何在新创建的 XBRL 实例中添加项目。

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

添加脚注链接

Aspose.Finance 允许您在新创建的 XBRL 实例中添加脚注链接。为此,API 提供了脚注链接班级。

以下代码片段演示了如何在新创建的 XBRL 实例中添加脚注链接。

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

添加角色参考

Aspose.Finance 允许您在新创建的 XBRL 实例中添加角色引用。为此,API 提供了角色参考班级。

以下代码片段演示了如何在新创建的 XBRL 实例中添加角色引用。

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

添加圆弧角色参考

Aspose.Finance 允许您在新创建的 XBRL 实例中添加弧角色引用。为此,API 提供了Arcrole参考资料班级。

以下代码片段演示了如何在新创建的 XBRL 实例中添加 arc 角色引用。

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