草庐IT

LINQ_ENABLED

全部标签

c# - 为什么此 LINQ 抛出 NullReferenceException?

privateSmtpClientgetServer(){return(fromeindoc.Elements("emailsetting")selectnewSmtpClient(){Host=e.Attribute("server").Value,Port=Convert.ToInt32(e.Attribute("port").Value)}).FirstOrDefault();}xml配置文件:为什么抛出异常:NullReferenceException未处理对象引用未设置到对象的实例。我是LINQ的新手,请帮忙。 最佳答案

c# - Linq 到 XML : Get all nodes that contain certain children

我有以下XML结构:而且我需要查询具有RelatedTo属性值为5的子关系的所有Capabilities。到目前为止,我已经尝试过以下查询,但我得到了一组“空引用异常”,但我不知道该怎么做。varresult=root.Elements("Capability").Where(c=>c.Elements("Relations").Where(r=>r.Attribute("RelatedTo").Value=="5"&&r.Attribute("").Value==Enum.GetName(typeof(RelationTypes),RelationTypes.Children)).A

c# - XElement 的 Linq to xml 部分

我正在使用LinqtoXML将列表保存到XML字符串中。我要获取的xml字符串:xxx23yyy25C#代码:ListpeopleList=newList();peopleList.Add(newPeoples(){Name="xxx",Age=23});peopleList.Add(newPeoples(){Name="yyy",Age=25});varpeople(fromiteminpeopleListselectnewXElement("people",newXAttribute("name",item.Name),newXAttribute("age",item.Age)))

c# - 使用 Linq to XML C# 解析 xml 字符串并检索其属性值

我对LinqtoXML很陌生,并尝试在C#中使用LinqtoXML解析xml字符串并检索其属性值。我的XML字符串看起来像:.....................我想从pub节点获取“id”和“lang”的值,并从configitem节点获取名为“working_status”的属性的值。现在,当我将上述xml作为字符串参数(即myXmlData)时,通过执行XmlDocumentdoc=newXmlDocument();doc.LoadXml(myXmlData);XmlNodeListpublicationsNodeList=doc.SelectNodes("//configu

c# - 如何使用 LINQ to XML 接收列表格式的数据

使用c#、.net4.5昨天我问的是howtoreadxmlfile.正如昨天解释的那样,我可以使用Descendants()和Elements()用于获取我的文件所需的元素。现在,我有一些实体的xml文件HarrisonFORDUnknownName2000UnknownGenrefc29b1cf-be41-4ed8-b101-5355396fef10UnknownAuthorUnknownName2000UnknownGenre29b6d74b-71b3-4df6-af0b-d676ff5d23ad...我想要什么-获取Books列表(如List),其中Book-它是一个单独的实体

c# - 如何使用 Linq to XML 获取数组数组?

如何获得所有流派的列表?现在我只得到每首歌曲的第一个流派。XML文件:HighHopesRockAmericanImaginePopUnpluggedC#代码:publicvoidListGenres(){System.Xml.Linq.XElementxLibrary=System.Xml.Linq.XElement.Load(@"c:\Library.xml");System.Xml.Linq.XElementxSongs=xLibrary.Element("Songs");System.Collections.Generic.IEnumerablegenres=fromcodei

c# - 如何使用 LINQ 对具有以下结构的 XML 数据进行分组和求和?

XML结构:LoremipsumdolorsitametLoremipsum73LoremipsumdolorsitametLoremipsum3LoremipsumdolorsitametLoremipsum10LoremipsumdolorsitametLoremipsum49我需要对所有地点的事件类型进行分组,并获取每种事件类型的总人数。我能想到的就是这个:varevent_types=fromeventindata.Elements("Event").Attributes("type")groupeventbyevent.Valueintogselectg;但这只是分组,我完全

c# - 使用 linq 搜索 Xml 文档不返回任何内容

我正在尝试学习如何在C#中使用XML保存和提取数据,尽管我已经阅读了此处类似问题的各种答案,但我无法理解为什么我的语句没有返回任何内容。我正在编写的程序只是一个测试,其中我在xml文档中保存了关于几部电影的数据,现在我正试图根据它们的成本检索其中的一些。这是我为搜索编写的类:classExtractData{privateXDocument_xdoc;publicListSearchByCost(doublecost){_xdoc=XDocument.Load(FileLocation.XmlFileLocation);Listlist=newList();varmovies=from

c# - 如何使用 LINQ 对 XML 数据执行 OrderBy?

我在XML文件中有如下数据:www.google.com/ncr29/06/20175:27:25PMwww.yahoo.com10/03/20175:30:25PMwww.google.com/ncr23/01/20145:27:25PM我的目标是根据history-date对这些数据进行分组和排序。我正在使用以下代码来实现此目的:XDocumenthistory=XDocument.Load("history.xml");vardetails=fromcinhistory.Descendants("history-item")groupcbyc.Element("history-d

c# - 在 C# 中使用 LINQ-To-XML 解析具有多个列表和类对象的 XML 数据

假设我要解析以下XML文件://ListofEmployees11a//ListofDependentsofasingleemployeea150a252//UniqueperEmp1D1-------------以下是上述文件的类结构:publicclassEmployee{publicintid{get;set;}publicstringname{get;set;}publicListDependents{get;set;}publicDepartmentDepartment{get;set;}}publicclassDependents{publicstringname{get;