Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将XSD.exe与attributeGroup ref一起使用_C#_Xml_Xsd_Xsd.exe - Fatal编程技术网

C# 如何将XSD.exe与attributeGroup ref一起使用

C# 如何将XSD.exe与attributeGroup ref一起使用,c#,xml,xsd,xsd.exe,C#,Xml,Xsd,Xsd.exe,使用withref时,我在使用时遇到问题。我用它来生成C#类 这是我的XSD: <?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"

使用with
ref
时,我在使用时遇到问题。我用它来生成C#类

这是我的XSD:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           elementFormDefault="qualified"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           version="1.0">

  <xs:attributeGroup name="PersonBaseAttributes">
    <xs:attribute name="Name" type="xs:string" use="required" /> <!-- Missing in .CS -->
    <xs:attribute name="Born" type="xs:dateTime" use="required" /> <!-- Missing in .CS -->
  </xs:attributeGroup>

  <xs:attributeGroup name="SalesAttributes">
    <xs:attributeGroup ref="PersonBaseAttributes" />
    <xs:attribute name="Sales" type="xs:int" use="required" />
  </xs:attributeGroup>

  <xs:attributeGroup name="BossAttributes">
    <xs:attributeGroup ref="PersonBaseAttributes" />
    <xs:attribute name="Department" type="xs:string" use="required" />
  </xs:attributeGroup>

  <xs:element name="Boss" nillable="true" type="BossPerson" />
  <xs:element name="Sales" nillable="true" type="SalesPerson" />
  <xs:complexType name="SalesPerson">
    <xs:attributeGroup ref="SalesAttributes" />
  </xs:complexType>
    <xs:complexType name="BossPerson">
    <xs:attributeGroup ref="BossAttributes" />
  </xs:complexType>
</xs:schema>

XML模式在我看来是正确的,没有属性
Name
Born
的元素
Boss
Sales
将对模式无效(例如,当模式提供时,氧气确实需要这些属性)


请注意,生成的代码由分部类组成。该工具是否可以在其他地方生成其他属性?

我也有同样的问题。我认为xsd.exe不支持嵌套的属性组:

不幸的是,没有生成其他类/文件。我也有同样的问题。你找到解决办法了吗?@ParvSharma-不幸的是没有。在我的例子中,我们是手动操作的。这是一个答案。答案是“你不能那样做,它不受支持”。如果你觉得这是不正确的或没有用的,正确的做法是对答案投反对票,而不是对其进行标记。
public partial class SalesPerson {

    private int salesField;

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public int Sales {
        get {
            return this.salesField;
        }
        set {
            this.salesField = value;
        }
    }
}

public partial class BossPerson {

    private string departmentField;

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string Department {
        get {
            return this.departmentField;
        }
        set {
            this.departmentField = value;
        }
    }
}
xsd.exe foo.xsd /c