특정 방식으로 직렬화하려고하는 xsd가 있습니다. 다음과 같이 원하는 것을 얻을 수는 있지만 문제는 xsd2code가 아무 곳에서도 완전히 사용되지 않는 추가 클래스를 생성한다는 것입니다. 내가 잘못하고 있니? 또 다른 속임수가 있습니까?추가 클래스를 만들지 않고 xsd2code에서 XmlArrayAttribute 및 XmlArrayItemAttribute를 만드는 방법
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" >
<xsd:element name="UITranslatorConfiguration" >
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Queries" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Queries">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Query" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Query">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="QueryID" type="xsd:string" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:schema>
XML 출력 I 원하는 :
<UITranslatorConfiguration>
<Queries>
<Query QueryID="queryID1">someQueryText</Query>
<Query QueryID="queryiq2">someQueryText2</Query>
<Query QueryID="queryiq3">someQueryText3</Query>
</Queries>
<UITranslatorConfiguration>
가 생성하는 코드 :
이 미세이다
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xsd2Code", "3.4.0.38968")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class UITranslatorConfiguration {
[EditorBrowsable(EditorBrowsableState.Never)]
private List<Query> queriesField;
private static System.Xml.Serialization.XmlSerializer serializer;
public UITranslatorConfiguration() {
this.queriesField = new List<Query>();
}
[System.Xml.Serialization.XmlArrayAttribute(Order=0)]
[System.Xml.Serialization.XmlArrayItemAttribute("Query", IsNullable=false)]
public List<Query> Queries {
get {
return this.queriesField;
}
set {
this.queriesField = value;
}
}
}
이 미세이다
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xsd2Code", "3.4.0.38968")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class Query {
[EditorBrowsable(EditorBrowsableState.Never)]
private string queryIDField;
[EditorBrowsable(EditorBrowsableState.Never)]
private string valueField;
private static System.Xml.Serialization.XmlSerializer serializer;
[System.Xml.Serialization.XmlAttributeAttribute()]
public string QueryID {
get {
return this.queryIDField;
}
set {
this.queryIDField = value;
}
}
[System.Xml.Serialization.XmlTextAttribute()]
public string Value {
get {
return this.valueField;
}
set {
this.valueField = value;
}
}
}
이것은 좋지 않습니다. 이것은 왜 그리고 왜 왔습니까? 그것은 전혀 사용되지 않습니다. xsd2code가이 클래스를 생성하지 않게하려면 어떻게해야합니까?
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xsd2Code", "3.4.0.38968")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class Queries {
[EditorBrowsable(EditorBrowsableState.Never)]
private List<Query> queryField;
private static System.Xml.Serialization.XmlSerializer serializer;
public Queries() {
this.queryField = new List<Query>();
}
[System.Xml.Serialization.XmlElementAttribute("Query", Order=0)]
public List<Query> Query {
get {
return this.queryField;
}
set {
this.queryField = value;
}
}
}
해결 되었습니까? – Mightymuke
@Mightymuke 나는하지 않았다. 개체 모델에 여분의 클래스를 남겨 두었습니다. 그곳에 들어가서 아무 것도 아프지 않습니다. 사용하지 않는 코드는 파일을 압축하고 최소한의 코드에 대한 나의 욕구에 어긋나지 만 살 수 있습니다. – EbbnFlow
나는 생성 된 코드 (예 : 필드 이름 등)와 비슷한 "문제"를 가졌습니다. 좋고 깨끗한 엔티티 클래스를 작성하고 [AutoMapper] (https://github.com/AutoMapper/AutoMapper)를 사용하여 데이터를 복사했습니다. 즉, 생성 된 클래스를 처리 할 필요가 없었으며 또한 [반부패 계층] (http : //www.markhneedham.com/blog/2009/07/07/도메인 기반 디자인 - 안티 - 부패 - 레이어 /). 그러나 xsd2code를 빠르게 살펴보고 재미있는 것을 찾으면 업데이트 할 것입니다. – Mightymuke