简体   繁体   中英

How can I read an XML file and store into a OODBMSs (Siaqodb) with LinQ?

XMl-ODBMSs noob here, so I was trying to find out the most efficient way to read an xml file and store it as data objects on my Siaqodb. I've been looking for tutorial and its been hard to find any. If anybody could help me out with, I'd be greatful.

<MusicList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Version>0</Version>
    <Music>
        <Album>Atabales Mix</Album>
        <AlbumArtist>Desconocido</AlbumArtist>
        <AlbumCover>http://192.168.100.5:9000/rpc/cat/IVANS/Covers/Grupo De Palos - Atabales Mix.jpg</AlbumCover>
        <Artist>Grupo De Palos</Artist>
        <ArtistCover>http://192.168.100.5:9000/rpc/cat/IVANS/Covers/Grupo De Palos_300_300.jpg</ArtistCover>
        <Genre>Atabal</Genre>
        <GenreCover>http://192.168.100.5:9000/rpc/cat/IVANS/Covers/Atabal_300_300.jpg</GenreCover>
        <Path>http://192.168.100.5:9000/rpc/cat/IVANS/Music/Atabal/GRUPO DE PALO BANI - TRACK 04.MP3</Path>
        <Title>Dolores</Title>
    </Music>
    <Music>
        <Album>Atabales Mix</Album>
        <AlbumArtist>Desconocido</AlbumArtist>
        <AlbumCover>http://192.168.100.5:9000/rpc/cat/IVANS/Covers/Grupo De Palos - Atabales Mix.jpg</AlbumCover>
        <Artist>Grupo De Palos</Artist>
        <ArtistCover>http://192.168.100.5:9000/rpc/cat/IVANS/Covers/Grupo De Palos_300_300.jpg</ArtistCover>
        <Genre>Atabal</Genre>
        <GenreCover>http://192.168.100.5:9000/rpc/cat/IVANS/Covers/Atabal_300_300.jpg</GenreCover>
        <Path>http://192.168.100.5:9000/rpc/cat/IVANS/Music/Atabal/GRUPO DE PALO BANI - TRACK 01.MP3</Path>
        <Title>Espiritu divino</Title>
    </Music>
</MusicList>

Thanks in advance!

So I resolved the problem by using the XDocument method .Load(), calling the elements of the object and iterating a foreach loop with a condition inside. Then, I stored those objects into the database.

namespace WindowsFormsApplication5
{
    public class Program
    {
        public class Canciones
        {
            public string Album { get; set; }
            public string AlbumArtist { get; set; }
            public string AlbumCover { get; set; }
            public string Artist { get; set; }
            public string ArtistCover { get; set; }
            public string Genre { get; set; }
            public string GenreCover { get; set; }
            public string Path { get; set; }
            public string Title { get; set; }
            public int OID { get; set; }
        }
       public static void Main()
        {
            int counter = 0;
            Siaqodb siaqodb = new Siaqodb(@"d:\Siaqodb\database\TEST\");

           List<Canciones> musicList = (from m in XDocument.Load(@"C:\Users\ivan_000\Desktop\MusicList.xml")
                                           .Descendants("Music")
                                           select new Canciones{
                                           Album = m.Element("Album").Value,
                                           AlbumArtist = m.Element("AlbumArtist").Value,
                                           AlbumCover = m.Element("AlbumCover").Value,
                                           Artist = m.Element("Artist").Value,
                                           ArtistCover = m.Element("ArtistCover").Value,
                                           Genre = m.Element("Genre").Value,
                                           GenreCover = m.Element("GenreCover").Value,
                                           Path = m.Element("Path").Value,
                                           Title = m.Element("Title").Value,
                                           OID = musicList.Count()                                          

                                           }).ToList();

                        foreach(Cancion cancion in musicList)
                        {
                            counter++;
                            if (counter <= 100)
                                    siaqodb.StoreObject(cancion);   
                            else
                                break;                  
                        }

        }

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM