c# - Xsd.exe 使用 SubstitutionGroup/anytype 生成不可用的代码

标签 c# xml xsd xsd.exe xbrl

好的。我正在尝试从以下位置生成 C# 类: http://www.xbrl.org/2003/xbrl-instance-2003-12-31.xsd (基本上是 xbrl 模式)。

我对元组和项目有疑问。

这是 xsd 的样子:

  <element name="tuple" type="anyType" abstract="true">
    <annotation>
      <documentation>
      Abstract tuple element used as head of tuple substitution group
      </documentation>
    </annotation>
  </element>

  <element name="xbrl">
    <annotation>
      <documentation>
      XBRL instance root element.
      </documentation>
    </annotation>
    <complexType>
      <sequence>
        <element ref="link:schemaRef" minOccurs="1" maxOccurs="unbounded" />
        <element ref="link:linkbaseRef" minOccurs="0" maxOccurs="unbounded" />
        <element ref="link:roleRef" minOccurs="0" maxOccurs="unbounded" />
        <element ref="link:arcroleRef" minOccurs="0" maxOccurs="unbounded" />
        <choice minOccurs="0" maxOccurs="unbounded">
          <element ref="xbrli:item"/>
          <element ref="xbrli:tuple"/>
          <element ref="xbrli:context"/>
          <element ref="xbrli:unit"/>
          <element ref="link:footnoteLink"/>
        </choice>
      </sequence>
      <attribute name="id" type="ID" use="optional" />
      <anyAttribute namespace="http://www.w3.org/XML/1998/namespace"
                    processContents="lax" />
    </complexType>
  </element>

序列的生成属性如下所示:

[System.Xml.Serialization.XmlElementAttribute("context", typeof(context))]
[System.Xml.Serialization.XmlElementAttribute("item", typeof(object))]
[System.Xml.Serialization.XmlElementAttribute("tuple", typeof(object))]
[System.Xml.Serialization.XmlElementAttribute("unit", typeof(unit))]
[System.Xml.Serialization.XmlElementAttribute("footnoteLink", typeof(footnoteLink),
                             Namespace="http://www.xbrl.org/2003/linkbase")]
public object[] Items {
  get {
    return this.itemsField;
  }
  set {
    this.itemsField = value;
  }
}

基本上不生成tuple和item抽象基类。因此,即使其他模式具有 substitutiongroup="tuple",我也无法将其放入。(我可以,但它不会序列化)。

最佳答案

Xsd.exe 无法处理 W3C XSD 标准中的一些更复杂的结构。因此,您可能不得不寻求第三方数据绑定(bind)产品。

可以在此处找到产品列表(但它们都有点过时了)

我们在 Liquid XML Data Binder 上取得了不错的成绩.

关于c# - Xsd.exe 使用 SubstitutionGroup/anytype 生成不可用的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16097675/

相关文章:

C#:为什么我的 SQL 查询中缺少 .Where() 条件之一?

c# - 建议简化我的体系结构... asp.net mvc

mysql - 从 XML 导出到 MySQL 键和值

java - 似乎无法在 android 中解析 xml 文件而不出现 saxparser 意外 token 错误

xml - XML Schema 中的属性/元素共现约束

java - SonarQube 抛出 '' NullPointer 异常可能会抛出“对于从 xsd 文件在 java 文件中创建的变量的错误”

c# - ASP .NET WebAPI 无法访问路由

c# - 用于链接 iPhone、Android 和 .net 桌面应用程序的 Direct Connect P2P 库

c# - 如何创建忽略命名空间且不检查字符的 XmlTextReader

java - 根据 XSD 验证 XML 中的无效属性