2009-08-17 2 views
2

XSD를 작성했으며 XSD.exe를 .xsd 파일 위에 실행했습니다. 열거 형 값으로 제한되는 내 간단한 유형은 출력 된 .cs 파일에서 열거 형으로 생성되지 않는 것 같습니다. 예를 들어XSD.exe/dataset이 내 xsd 파일에서 열거 형을 생성하지 않습니다.

, 내 XSD는 다음과 같습니다

<xs:element name="ItemList" nillable="false"> 
    <xs:complexType> 
     <xs:sequence minOccurs="1" maxOccurs="1"> 
      <xs:element name="Item" type="ItemType" minOccurs="1" maxOccurs="unbounded" nillable="false"> 
      </xs:element> 
     </xs:sequence> 
    </xs:complexType> 
</xs:element> 
<xs:complexType name="ItemType"> 
    <xs:sequence maxOccurs="1" minOccurs="1"> 
     <!-- other complex types, etc... --> 
    </xs:sequence> 
    <xs:attribute name="Market" type="MarketType" use="required"> 
    </xs:attribute> 
    <xs:attribute name="Category" type="CategoryType" use="required" /> 
</xs:complexType> 
<xs:simpleType name="CategoryType"> 
    <xs:restriction base="xs:string"> 
     <xs:enumeration value="Mild" /> 
     <xs:enumeration value="Hot" /> 
    </xs:restriction> 
</xs:simpleType> 
<xs:simpleType name="MarketType"> 
    <xs:restriction base="xs:string"> 
     <xs:enumeration value="Weak" /> 
     <xs:enumeration value="Strong" /> 
    </xs:restriction> 
</xs:simpleType> 

내가 XSD.exe가 출력 된 .cs 파일 내 간단한 유형의 각각에 대한 XML 열거 속성을하지 말았어야 실행? This link says that it should. 어쩌면 내가 뭔가 잘못하고있는 걸까요? 내 .cs 파일에서 열거 형을 볼 수 없습니다.

추가 정보가 필요하면 알려 주시면 감사하겠습니다.

감사합니다.

UPDATE : I 클래스 (/ C 스위치)을 생성 된시기 나, 데이터 세트를 생성하기 위해 (/ D 스위치) XSD.exe를 사용 하였다 보인다

. 클래스를 생성하도록 설정 한 후 제대로 작동했습니다.

답변

2

(부분적으로) 나는 당신의 경우에 어떻게되는지 모르는 생성 - 나는 enum.xsd에 코드를 복사 그것에 xsd.exe 실행 - 여기 결과입니다 :

//------------------------------------------------------------------------------ 
// <auto-generated> 
//  This code was generated by a tool. 
//  Runtime Version:2.0.50727.4016 
// 
//  Changes to this file may cause incorrect behavior and will be lost if 
//  the code is regenerated. 
// </auto-generated> 
//------------------------------------------------------------------------------ 

using System.Xml.Serialization; 

// 
// This source code was auto-generated by xsd, Version=2.0.50727.3038. 
// 


/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)] 
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)] 
public partial class ItemList { 

    private ItemType[] itemField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlElementAttribute("Item", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public ItemType[] Item { 
     get { 
      return this.itemField; 
     } 
     set { 
      this.itemField = value; 
     } 
    } 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
public partial class ItemType { 

    private MarketType marketField; 

    private CategoryType categoryField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public MarketType Market { 
     get { 
      return this.marketField; 
     } 
     set { 
      this.marketField = value; 
     } 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    public CategoryType Category { 
     get { 
      return this.categoryField; 
     } 
     set { 
      this.categoryField = value; 
     } 
    } 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")] 
[System.SerializableAttribute()] 
public enum MarketType { 

    /// <remarks/> 
    Weak, 

    /// <remarks/> 
    Strong, 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")] 
[System.SerializableAttribute()] 
public enum CategoryType { 

    /// <remarks/> 
    Mild, 

    /// <remarks/> 
    Hot, 
} 

나는 두 개의 enum을 가지고있다. CategoryTypeMarketType.

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema id="TheParentNode" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    ..... (inserted your code here) ....... 
</xs:schema> 

을하고 나는 그것을 XSD.EXE을 실행 :

내가 한 모든

<xsl:schema> 태그로 XSD 코드를 넣어 위의 enum.cs 파일을 만든
xsd.exe enum.xsd /c 

.

XSD.EXE의 버전은 무엇입니까? .NET의 어떤 버전을 사용하고 있습니까?

정의 형 simpleType이 스키마에 모든 필드가 사용되지 않는 경우 마크가

1

저에게 맞나요? 하지만 스키마 요소를 추가하고 ItemType 안에 요소를 삽입해야했습니다.

<xs:schema 
    elementFormDefault ="qualified" 
    targetNamespace  ="urn:Jon.Stackoverflow._2009aug.Example" 
    xmlns:tns    ="urn:Jon.Stackoverflow._2009aug.Example" 
    xmlns:xs    ="http://www.w3.org/2001/XMLSchema" 
    > 


<xs:element name="ItemList" nillable="false"> 
    <xs:complexType> 
    <xs:sequence minOccurs="1" 
       maxOccurs="1"> 
     <xs:element name="Item" 
        type="tns:ItemType" 
        minOccurs="1" 
        maxOccurs="unbounded" 
        nillable="false"> 
     </xs:element> 
    </xs:sequence> 
    </xs:complexType> 
</xs:element> 

<xs:complexType name="ItemType"> 
    <xs:sequence maxOccurs="1" minOccurs="1"> 
    <xs:element type="xs:int" name="num"/> 
    </xs:sequence> 
    <xs:attribute name="Market" 
       type="tns:MarketType" 
       use="required"> 
    </xs:attribute> 
    <xs:attribute name="Category" type="tns:CategoryType" use="required" /> 
</xs:complexType> 

<xs:simpleType name="CategoryType"> 
    <xs:restriction base="xs:string"> 
    <xs:enumeration value="Mild" /> 
    <xs:enumeration value="Hot" /> 
    </xs:restriction> 
</xs:simpleType> 

<xs:simpleType name="MarketType"> 
    <xs:restriction base="xs:string"> 
    <xs:enumeration value="Weak" /> 
    <xs:enumeration value="Strong" /> 
    </xs:restriction> 
</xs:simpleType> 

</xs:schema> 

그것은이

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")] 
[System.SerializableAttribute()] 
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:Jon.Stackoverflow._2009aug.Example")] 
public enum MarketType { 

    /// <remarks/> 
    Weak, 

    /// <remarks/> 
    Strong, 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")] 
[System.SerializableAttribute()] 
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:Jon.Stackoverflow._2009aug.Example")] 
public enum CategoryType { 

    /// <remarks/> 
    Mild, 

    /// <remarks/> 
    Hot, 
} 
+0

귀하의 예는 제 경우에 효과가있었습니다. 전에는 생성 된 유형이 문자열이었습니다. 'xmlns : tns = "mynamespace"를 추가하고 속성 선언에'tns :'를 사용하면 생성 된 enum 유형이 생겼습니다. –

0

, 그 열거가 .cs 결과 파일에 표시되지 않습니다.

마찬가지로, 종류에 XS 사용하지만 조합 인 경우 : 문자열ENUM 여전히 생성 .cs 파일에서 표현되지된다.

그러나 스키마에 simpleType이있는 필드가있는 경우 (즉,)다른 유형의 합집합이 아닐 경우 출력 .cs 파일에 표시됩니다.

관련 문제