2012-08-29 26 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; } 
}