2012-08-29 56 views
0

是否有任何XSD2Code或xsd.exe工具或版本可以與XSD2Code一起生成C#實體?將XSD轉換爲帶有工作註釋的C#的免費工具/擴展

XSD2Code和xsd.exe都會忽略註釋(對於XSD2Code,EnableSummaryComment只是無法正常工作),我不想花時間分析和更改它們後面的源代碼......有人知道是否有充分的工作和自由的選擇?

回答

0

你有什麼樣的例子嗎?例如,xsd2code這

<xs:attribute name="Test" use="optional"> 
    <xs:annotation> 
     <xs:documentation>Test data number when combined with schema name provides the stub response.</xs:documentation> 
    </xs:annotation> 
    <xs:simpleType> 
     <xs:restriction base="xs:string"> 
      <xs:minLength value="1"/> 
      <xs:maxLength value="50"/> 
     </xs:restriction> 
    </xs:simpleType> 
</xs:attribute> 

產生這種

/// <summary> 
/// Test data number when combined with schema name provides the stub response. 
/// </summary> 
[System.Xml.Serialization.XmlAttributeAttribute()] 
public string Test { get; set; } 

你不同的東西后?

+0

我無法獲得用xsd2code生成的

......甚至將參數設置爲正確的值。但是已經有一段時間了(8月29日),我會審查它。 – Mirek

0

我剛剛用xsd2code和下面的xsd進行了測試。它看起來像xsd2code只支持註釋的屬性出現在生成的C#代碼。

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
      xmlns:example="http://example.org/annotations" 
      targetNamespace="http://example.org/annotations" 
      elementFormDefault="qualified"> 
    <xs:annotation> 
    <xs:documentation> 
     Demonstration of xs:annotation xs:documentation blocks to appear in xsd2code generated C# code. 
     Note: 
     - xsd.exe does not support annotations. Tested with NETFX 4.5.1 Tools. 
     - xsd2code only for attributes. Teste with version 3.4.0.32990. 
    </xs:documentation> 
    </xs:annotation> 
    <xs:element name="root" type="example:root"> 
    <xs:annotation> 
     <xs:documentation>Information root.</xs:documentation> 
    </xs:annotation> 
    </xs:element> 
    <xs:complexType name="root"> 
    <xs:annotation> 
     <xs:documentation>Complex root type.</xs:documentation> 
    </xs:annotation> 
    <xs:all> 
     <xs:annotation> 
     <xs:documentation> 
      Elements in any order. 
     </xs:documentation> 
     </xs:annotation> 
     <xs:element name="TestElement" type="example:string50"> 
     <xs:annotation> 
      <xs:documentation> 
      Test data in element. 
      </xs:documentation> 
     </xs:annotation> 
     </xs:element> 
    </xs:all> 
    <xs:attribute name="TestAttribute" use="optional" type="example:string50"> 
     <xs:annotation> 
     <xs:documentation> 
      Optional test data in attribute. 
     </xs:documentation> 
     </xs:annotation> 
    </xs:attribute> 
    </xs:complexType> 
    <xs:simpleType name="string50"> 
    <xs:restriction base="xs:string"> 
     <xs:minLength value="1"/> 
     <xs:maxLength value="50"/> 
    </xs:restriction> 
    </xs:simpleType> 
    <xs:annotation> 
    <xs:documentation> 
     End of the XSD. 
    </xs:documentation> 
    </xs:annotation> 
</xs:schema> 
1

XmlSchemaClassGenerator支持元素,屬性和類型的註釋。它還從限制中生成XML文檔,並且它是開源的。充分披露:我是主要作者。

/// <summary> 
/// <para>Complex root type.</para> 
/// <para>Information root.</para> 
/// </summary> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("XmlSchemaClassGenerator", "1.0.0.0")] 
[System.SerializableAttribute()] 
[System.Xml.Serialization.XmlTypeAttribute("root", Namespace="http://example.org/annotations")] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlRootAttribute("root", Namespace="http://example.org/annotations")] 
public partial class Root 
{ 

    /// <summary> 
    /// <para> 
    ///   Test data in element. 
    ///   </para> 
    /// <para xml:lang="en">Minimum length: 1.</para> 
    /// <para xml:lang="en">Maximum length: 50.</para> 
    /// </summary> 
    [System.ComponentModel.DataAnnotations.MinLengthAttribute(1)] 
    [System.ComponentModel.DataAnnotations.MaxLengthAttribute(50)] 
    [System.Xml.Serialization.XmlElementAttribute("TestElement", Namespace="http://example.org/annotations")] 
    public string TestElement { get; set; } 

    /// <summary> 
    /// <para> 
    ///   Optional test data in attribute. 
    ///  </para> 
    /// <para xml:lang="en">Minimum length: 1.</para> 
    /// <para xml:lang="en">Maximum length: 50.</para> 
    /// </summary> 
    [System.ComponentModel.DataAnnotations.MinLengthAttribute(1)] 
    [System.ComponentModel.DataAnnotations.MaxLengthAttribute(50)] 
    [System.Xml.Serialization.XmlAttributeAttribute("TestAttribute", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public string TestAttribute { get; set; } 
}