Microsoft SDKのxsd.exeを使用して、最初にxmlファイルのスキーマを生成し、次に以前に生成されたxsdファイルのC#ファイルを生成しました。これが私のxmlファイルです:
<event topic="event.system.visualization.initialization.response" subject="CIBEK204Test0" producer="de.cibek.configurator" timeToLive="0" too="1351252459919" duration="0">
<payload>
<![CDATA[
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<building>
<floor name="">
<location name="Wohnen">
<item category="event.environment.apartment.window" groupaddress="10248" location="Wohnen" location.floor="" location.specification="Mitte links"/>
</location>
</floor>
</building>
]]>
</payload>
<properties/>
<traces/>
これで、生成されたxsd:
<?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="event">
<xs:complexType>
<xs:sequence>
<xs:element name="payload" type="xs:string" minOccurs="0" msdata:Ordinal="0" />
<xs:element name="properties" type="xs:string" minOccurs="0" msdata:Ordinal="1" />
<xs:element name="traces" type="xs:string" minOccurs="0" msdata:Ordinal="2" />
</xs:sequence>
<xs:attribute name="topic" type="xs:string" />
<xs:attribute name="subject" type="xs:string" />
<xs:attribute name="producer" type="xs:string" />
<xs:attribute name="timeToLive" type="xs:string" />
<xs:attribute name="too" type="xs:string" />
<xs:attribute name="duration" 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="event" />
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
そして、生成されたcsファイル:
using System.Xml.Serialization;
//
// This source code was auto-generated by xsd, Version=4.0.30319.17929.
//
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
[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 @event {
private string payloadField;
private string propertiesField;
private string tracesField;
private string topicField;
private string subjectField;
private string producerField;
private string timeToLiveField;
private string tooField;
private string durationField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string payload {
get {
return this.payloadField;
}
set {
this.payloadField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string properties {
get {
return this.propertiesField;
}
set {
this.propertiesField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string traces {
get {
return this.tracesField;
}
set {
this.tracesField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string topic {
get {
return this.topicField;
}
set {
this.topicField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string subject {
get {
return this.subjectField;
}
set {
this.subjectField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string producer {
get {
return this.producerField;
}
set {
this.producerField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string timeToLive {
get {
return this.timeToLiveField;
}
set {
this.timeToLiveField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string too {
get {
return this.tooField;
}
set {
this.tooField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string duration {
get {
return this.durationField;
}
set {
this.durationField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
[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 @event[] itemsField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("event")]
public @event[] Items {
get {
return this.itemsField;
}
set {
this.itemsField = value;
}
}
}
今私の質問は:なぜxsd.exeはCDATAに埋め込まれたxmlコードを無視するのですか?xsd.exeにCDATAを無視しないように強制する可能性はありますか?または、2つのxsdファイルとcsファイルを生成し、最初のファイル(イベントを含む)に別のxmlファイルを含むCDATAノードがあり、生成されたコードでそれらをリンクすることを通知することは可能ですか?
長い投稿で申し訳ありませんが、誰かが私を助けてくれることを願っています:)