tags:

views:

22

answers:

1

Hi , I need to generate custom xml from Itunes xml library file. I have attached both the itune's xml library excerpt and custom xml format I need to generate. Can anyone pls guide me what would be the best way to get this job done.

I have no prior experience in xml handling in C#.any help would be appreciated. please find below t for sample itune's xml excerpt and custom xml need to be generated from it .

sampleItunexml_excerpt

<key>Major Version</key>
<integer>1</integer>  
<key>Music Folder</key>
<string>file://localhost/Users/shreekara/Music/iTunes/iTunes%20Media/</string>
<key>Library Persistent ID</key>
<string>8476AB39B21ED5A4</string>   
<key>Tracks</key>
<dict>
    <key>104</key>
    <dict>
    <key>Track ID</key>
    <integer>104</integer>
    <key>Name</key>
    <string>As I Am [Intro]</string>  
    <key>Album</key>
    <string>As I Am [The Super Edition]</string>        
    </dict>
</dict> 
<key>PlayLists</key>
<array>
    <dict>
        <key>Name</key>
        <string>Music</string>
        <key>Playlist ID</key>
        <integer>264</integer>
        <key>Playlist Persistent ID</key>
        <string>391658FB6AA44C69</string>
        <key>Distinguished Kind</key>
        <integer>4</integer>
        <key>Music</key>
        <true/>
        <key>All Items</key>
        <true/>                     
        <key>Playlist Items</key>
        <array>
            <dic>
                 <key>Track ID</key>
                 <integer>104</integer>
            </dict>
        </array>
    </dict>
</array>
</dict>
</plist>

CustomXML need to generate

<plist version= 1.0>
<dict>  <key>Library Persistent ID</key>
<string>8476AB39B21ED5A4</string>
<key>Music Folder</key>
<string>file://localhost/Users/shreekara/Music/iTunes/iTunes%20Media/</string>

<key>PlayLists</key>
<array>
    <dict>
    <key>All Items</key>
    <true/>
    <key>Distinguished Kind</key>
    <integer>4</integer>
    <key>Music</key>
    <true/>
    <key>Name</key>
    <string>Music</string>
    <key>Playlist ID</key>
    <integer>264</integer>

       <key>Playlist Items</key>
       <array>
        <dict>
        <key>Album</key>
        <string>As I Am [The Super Edition]</string> 
        <key>Name</key>
        <string>As I Am [Intro]</string>            
        <key>Track ID</key>
        <integer>104</integer>            
        </dict>

       </array>

    <key>Playlist Persistent ID</key>
    <string>391658FB6AA44C69</string>              
    </dict>
</array>

A: 

You will find the classes around XDocument and XElement useful.

In particular, you can use XElement.Elements() to get a collection of elements (XML tags) inside any particular tag, and then you can iterate over it using either:

Timwi