C# 如何使用XSD生成的类填充和调整XML
我使用xds.exe创建了以下类:C# 如何使用XSD生成的类填充和调整XML,c#,xml,xsd,C#,Xml,Xsd,我使用xds.exe创建了以下类: namespace vgtunesWPF { [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("cod
namespace vgtunesWPF
{
[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 Library
{
private LibraryTrack[] mediaField;
private string playListsField;
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Track", IsNullable = false)]
public LibraryTrack[] Media
{
get
{
return this.mediaField;
}
set
{
this.mediaField = value;
}
}
/// <remarks/>
public string PlayLists
{
get
{
return this.playListsField;
}
set
{
this.playListsField = 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 LibraryTrack
{
private string idField;
private string locationField;
private string titleField;
private string artistField;
private string albumField;
private string jaarField;
private string genreField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataType = "ID")]
public string ID
{
get
{
return this.idField;
}
set
{
this.idField = value;
}
}
/// <remarks/>
public string Location
{
get
{
return this.locationField;
}
set
{
this.locationField = value;
}
}
/// <remarks/>
public string Title
{
get
{
return this.titleField;
}
set
{
this.titleField = value;
}
}
/// <remarks/>
public string Artist
{
get
{
return this.artistField;
}
set
{
this.artistField = value;
}
}
/// <remarks/>
public string Album
{
get
{
return this.albumField;
}
set
{
this.albumField = value;
}
}
/// <remarks/>
public string Jaar
{
get
{
return this.jaarField;
}
set
{
this.jaarField = value;
}
}
/// <remarks/>
public string Genre
{
get
{
return this.genreField;
}
set
{
this.genreField = value;
}
}
}
}
名称空间vgtunesWPF
{
[System.CodeDom.Compiler.GeneratedCodeAttribute(“xsd”,“4.0.30319.1”)]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace=”“,IsNullable=false)]
公共部分类库
{
私人图书馆轨道[]媒体领域;
私有字符串播放字段;
///
[System.Xml.Serialization.XmlArrayItemAttribute(“Track”,IsNullable=false)]
公共图书馆轨道[]媒体
{
得到
{
返回此.mediaField;
}
设置
{
this.mediaField=值;
}
}
///
公共字符串播放列表
{
得到
{
返回此.playlisfield;
}
设置
{
this.playlisfield=值;
}
}
}
///
[System.CodeDom.Compiler.GeneratedCodeAttribute(“xsd”,“4.0.30319.1”)]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
公共部分类图书馆轨道
{
专用字符串字段;
私有字符串定位字段;
私有字符串标题字段;
私人弦乐艺术家领域;
私有字符串字段;
私有字符串jaarField;
私有字符串genreField;
///
[System.Xml.Serialization.xmlementAttribute(DataType=“ID”)]
公共字符串ID
{
得到
{
返回此.idField;
}
设置
{
this.idField=值;
}
}
///
公共字符串位置
{
得到
{
返回此.locationField;
}
设置
{
this.locationField=值;
}
}
///
公共字符串标题
{
得到
{
把这个还给我;
}
设置
{
this.titleField=值;
}
}
///
公共弦乐艺术家
{
得到
{
返回此.artistField;
}
设置
{
this.artistField=值;
}
}
///
公共字符串相册
{
得到
{
返回此.album字段;
}
设置
{
this.album字段=值;
}
}
///
公共字符串Jaar
{
得到
{
返回这个.jaarField;
}
设置
{
this.jaarField=值;
}
}
///
公共弦乐体裁
{
得到
{
返回此.genreField;
}
设置
{
this.genreField=值;
}
}
}
}
它用于创建以下XML:
<Library>
<Media>
<Track>
<ID>0</ID>
<Location>url</Location>
<Title>title</Title>
<Artist>artist</Artist>
<Album>album</Album>
<Jaar>year</Jaar>
<Genre>genre</Genre>
</Track>
<ID>1</ID>
<Location>url</Location>
<Title>title</Title>
<Artist>artist</Artist>
<Album>album</Album>
<Jaar>year</Jaar>
<Genre>genre</Genre>
</Track>
</Media>
</Library>
0
网址
标题
艺术家
专辑
年
体裁
1.
网址
标题
艺术家
专辑
年
体裁
因此,这里的问题是,我不知道如何在保留存储在xml中的数据的同时填充xml。听起来您想将现有xml数据与存储在类中的新数据合并
最好的方法是将xml反序列化到该类的一个实例中,进行更改,然后再次序列化。OK thx这是一个相当简单的答案:D真的需要开箱思考。