2010-10-14 54 views
0

HOWTO使用XSD生成的類,以填補和使用xds.exe我創建以下類調整XML

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; 
     } 
    } 
} 
} 

它被用來創建下面的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> 

這裏的問題因此是我不知道如何在保存數據的同時填充xml。

回答

1

聽起來好像你想要將現有的XML數據與存儲在類中的新數據合併。

做到這一點的最佳方法是將xml反序列化爲該類的實例,進行更改並重新序列化。

+0

OK thx這是一個相當簡單的答案:D真的需要在這裏想出來的框。 – 2010-10-14 12:09:55