本文介绍了有关于查询linq的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文件xml:



< Music>

< song>

< songalbum> Fearless< / songalbum>

< songid> 1< / songid> 



< songname> Love Story< / songname>

< songlinks> / Album / Fearless / Taylor Swift - Taylor Swift _专辑320 lossless.mp3< / songlinks>

< / song>

< / Music>



code xaml



var xmlelem = XElement.Load(@" XMLlistmusic.xml");

var song = from x in xmlelem.Descendants(" song")

// orderby prod.Element(" songname")。Value

选择p.Element(" songname")。值;



// var song2 = from p in 

songlist.DataContext = song;

file xml:

<Music>
<song>
<songalbum>Fearless</songalbum>
<songid>1</songid> 

<songname>Love Story</songname>
<songlinks>/Album/Fearless/Taylor Swift - Taylor Swift _ Album 320 lossless.mp3</songlinks>
</song>
</Music>

code xaml

var xmlelem = XElement.Load(@"XMLlistmusic.xml");
var song = from p in xmlelem.Descendants("song")
//orderby prod.Element("songname").Value
select p.Element("songname").Value;

// var song2=from p in 
songlist.DataContext = song;

我想给quey一个"where"  

ex:通过songname给歌曲链接...

谢谢你,

推荐答案

var xmlelem = XElement.Load(@"XMLlistmusic.xml");
var song = from p in xmlelem.Descendants("song")
           where p.Element("songname").Value.Equals("Love Story")
           select p.Element("songlinks").Value;


你可以在此处获取有关LINQ to XML的更多信息:

You can get more information on LINQ to XML here: http://msdn.microsoft.com/en-us/library/bb943906.aspx


这篇关于有关于查询linq的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 21:26