C# を使用してシリアル化した後の XML は次のようになります。このための C# クラスの定義方法を教えてください。
<select disablesorting=\"false\">"
<option attrib1="aa" attrib2="xx">fgdgf</option>
<option attrib1="aa" attrib2="yy">fgdgf</option>
</select>
前もって感謝します。
C# を使用してシリアル化した後の XML は次のようになります。このための C# クラスの定義方法を教えてください。
<select disablesorting=\"false\">"
<option attrib1="aa" attrib2="xx">fgdgf</option>
<option attrib1="aa" attrib2="yy">fgdgf</option>
</select>
前もって感謝します。
XML を実行するXSD.EXE
と、次のスキーマが得られます。
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="select">
<xs:complexType>
<xs:sequence>
<xs:element name="option" nillable="true" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent msdata:ColumnName="option_Text" msdata:Ordinal="2">
<xs:extension base="xs:string">
<xs:attribute name="attrib1" type="xs:string" />
<xs:attribute name="attrib2" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="disablesorting" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="select" />
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
そのスキーマをXSD.EXE
再度実行すると、次のクラスが生成されます。
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18052
//
// 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=4.0.30319.1.
//
/// <remarks/>
[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 select {
private selectOption[] optionField;
private string disablesortingField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("option", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=true)]
public selectOption[] option {
get {
return this.optionField;
}
set {
this.optionField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string disablesorting {
get {
return this.disablesortingField;
}
set {
this.disablesortingField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
public partial class selectOption {
private string attrib1Field;
private string attrib2Field;
private string valueField;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string attrib1 {
get {
return this.attrib1Field;
}
set {
this.attrib1Field = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string attrib2 {
get {
return this.attrib2Field;
}
set {
this.attrib2Field = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string Value {
get {
return this.valueField;
}
set {
this.valueField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[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 NewDataSet {
private select[] itemsField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("select")]
public select[] Items {
get {
return this.itemsField;
}
set {
this.itemsField = value;
}
}
}
これは次のように簡略化できます。
[Serializable]
[XmlType(AnonymousType=true)]
[XmlRoot(Namespace="", IsNullable=false)]
public partial class select {
[XmlElement("option")]
public selectOption[] option { get; set; }
/// <remarks/>
[XmlAttribute]
public string disablesorting { get; set; }
}
[System.Serializable]
[XmlType(AnonymousType=true)]
public partial class selectOption {
[XmlAttribute]
public string attrib1 { get; set; }
[XmlAttribute]
public string attrib2 { get; set; }
[XmlText]
public string Value { get; set; }
}
[System.Serializable]
[XmlType(AnonymousType=true)]
[XmlRoot(Namespace="", IsNullable=false)]
public partial class NewDataSet {
[XmlElement("select")]
public select[] Items { get; set; }
}