C# 如何读取XML文件并使用LinQ存储到OODBMS(Siaqodb)中?
XMl ODBMSs noob在这里,所以我试图找到读取XMl文件并将其作为数据对象存储在Siaqodb上的最有效方法。我一直在找教程,很难找到。如果有人能帮我,我会很感激的C# 如何读取XML文件并使用LinQ存储到OODBMS(Siaqodb)中?,c#,xml,linq,linq-to-entities,object-oriented-database,C#,Xml,Linq,Linq To Entities,Object Oriented Database,XMl ODBMSs noob在这里,所以我试图找到读取XMl文件并将其作为数据对象存储在Siaqodb上的最有效方法。我一直在找教程,很难找到。如果有人能帮我,我会很感激的 <MusicList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Version>0</Version> <Music> <Album>Atabales Mix&l
<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>
0
阿塔巴勒斯混合
Desconocido
http://192.168.100.5:9000/rpc/cat/IVANS/Covers/Grupo De Palos-Atabales Mix.jpg
帕洛斯集团
http://192.168.100.5:9000/rpc/cat/IVANS/Covers/Grupo De Palos_300_300.jpg
阿塔巴尔
http://192.168.100.5:9000/rpc/cat/IVANS/Covers/Atabal_300_300.jpg
http://192.168.100.5:9000/rpc/cat/IVANS/Music/Atabal/GRUPO 德帕洛巴尼-曲目04.MP3
多洛雷斯
阿塔巴勒斯混合
Desconocido
http://192.168.100.5:9000/rpc/cat/IVANS/Covers/Grupo De Palos-Atabales Mix.jpg
帕洛斯集团
http://192.168.100.5:9000/rpc/cat/IVANS/Covers/Grupo De Palos_300_300.jpg
阿塔巴尔
http://192.168.100.5:9000/rpc/cat/IVANS/Covers/Atabal_300_300.jpg
http://192.168.100.5:9000/rpc/cat/IVANS/Music/Atabal/GRUPO 德帕洛巴尼-曲目01.MP3
埃斯皮里图迪维诺
提前谢谢 因此,我通过使用XDocument方法.Load()解决了这个问题,调用了对象的元素,并迭代了一个包含条件的foreach循环。然后,我将这些对象存储到数据库中
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;
}
}
}
命名空间窗口窗体应用程序5
{
公共课程
{
公共类癌症
{
公共字符串相册{get;set;}
公共字符串{get;set;}
公共字符串{get;set;}
公共字符串艺术家{get;set;}
公共字符串ArtistCover{get;set;}
公共字符串类型{get;set;}
公共字符串GenreCover{get;set;}
公共字符串路径{get;set;}
公共字符串标题{get;set;}
公共整数OID{get;set;}
}
公共静态void Main()
{
int计数器=0;
Siaqodb Siaqodb=新的Siaqodb(@“d:\Siaqodb\database\TEST\”);
列表musicList=(从XDocument.Load(@“C:\Users\ivan\u 000\Desktop\musicList.xml”)中的m开始)
.后代(“音乐”)
选择新的癌症{
相册=m.Element(“相册”)值,
AlbumArtist=m.Element(“AlbumArtist”).值,
AlbumCover=m.Element(“AlbumCover”).值,
艺术家=m.元素(“艺术家”).值,
ArtistCover=m.元素(“ArtistCover”).值,
类型=m.元素(“类型”).值,
GenreCover=m.Element(“GenreCover”).值,
路径=m.Element(“路径”).值,
标题=m.元素(“标题”).值,
OID=musicList.Count()
}).ToList();
foreach(音乐列表中的Cancion Cancion)
{
计数器++;
如果(计数器您可以使用DataSet ReadXml方法轻松读取xml文件。您可以创建到数据库的连接和命令。该命令有4种方法:选择、更新、插入和删除。您可以使用Update或Insert方法保存数据集。这非常通用,请展示一些示例。您尝试了什么?我解决了问题通过使用.Load()方法从LinQ到XML包使用XDocument对象加载文件,从XML文件加载每个元素,并使用计数器变量迭代foreach循环,在100个对象上中断它,然后将它们存储到数据库中!。