草庐IT

c# - 根据C#中的日期从Xml中过滤数据

我需要帮助根据日期过滤xml文件,我拥有的这部分代码只根据用户名和地点打印出所有平均信息Runnerrun=newRunner();stringfilePath="runners.xml";//pathXDocumentxDoc=XDocument.Load(filePath);stringuserSelect=name;varaverageAddDistancequery=xDoc.Descendants("User").Where(w=>(string)w.Element("Name")==user).Select(s=>new{add=s.Elements("Attempts")

c# - 如何使用 LINQ 解析 XML header 和嵌套部分

XElementdocumentRoot=XElement.Parse(@"111123MainSt.MyCityAZ2111MainSt.OtherCityAL3222MainSt.CancelledCityAL23212");代码:varorders=documentRoot.Descendants("Order").Concat(documentRoot.Descendants("OrderCancelled")).Select(x=>new{OrderNumber=(int)x.Element("OrderNumber"),ShipAddress=(string)x.Eleme

c# - 如何正确使用 LINQ to XML?

我已经生成了这样的xml文件2121221221我的目标是获取IDWork、numRequest等元素。我试图以这种方式获取它们:foreach(XElementelindoc.Root.Elements()){if(el.Name=="Single_Request"){stringnum=el.Elements("numRequest").Value;//buthesays,thathecantdothis.Valuebecauseitdoestexistatall}}如何解决这个问题? 最佳答案 你有这个错误,因为Element

c# - ASP.NET 将 xml 字符串转换为字典

我有一个这样的xml文档:ModelRaggaeRate21我想从中创建一个字典,它将包含Name元素作为键,Value元素作为值。请帮助我。这是我写的代码,我想知道它是否足够高效:IDictionaryXmlToDictionary(stringdata){XElementrootElement=XElement.Parse(data);vardict=newDictionary();foreach(varelinrootElement.Elements()){if(el.Name.LocalName=="Key"){foreach(varsubinel.Elements()){st

c# - 从具有相同名称的多个元素和 xml 中另一个元素的属性值获取属性值

我有一个如下所示的xml文件:我试图从这些节点中选择一对信息:事件ID(12345)和元素选项的属性varnodeWithOptions=fromninxml.Descendants("event")selectnew{id=n.Attribute("id").Value,options=n.Elements("option").Attributes("href").ToString(),};不幸的是,这会为我的foreach循环中的选项生成以下内容:item.options="System.Xml.Linq.Extensions+d__8"我想要的是:12345、1234(是的,我不

c# - Linq to XML 选择每个具有特定属性的后代的后代

我找到了很多关于获取具有特定属性的后代的文章,但我似乎找不到任何关于使用LINQtoXML选择具有不同属性的多个后代的文章。因此,在下面的示例中,我需要选择所有Parentname=KenANDChildname=Lorna的Grandchildren。可能,我需要最多4个AND子句,因为我的真实XML比下面的示例更深。我可以通过代码选择Ken的所有子级,但找不到比这更深入的示例。非常感谢任何帮助 最佳答案 这里有多个选项,但我建议最简单的方法就是检查每个Grandchild:vargrandchildren=doc.Descend

C# LINQ 和 XML 获取子节点

获取节点值时出现问题。不确定为什么以下代码无法这样做。acceptedWindows7SecurityTechnicalImplementationGuideTheWindows7SecurityTechnicalImplementationGuide(STIG)ispublishedasatooltoimprovethesecurityofDepartmentofDefense(DoD)informationsystems.TherequirementsweredevelopedfromDoDconsensus,aswellastheWindows7SecurityGuideands

c# - 寻求有关在 XML XDocument 中查找元素和更新属性的帮助

我正在学习XML查询和Xdocuments,但在更新现有元素的属性时遇到了问题。这是我的WCF服务。第二部分有效(创建具有属性的新元素。问题是我的查询不能返回任何结果并且代码总是添加一个新元素。//thiswillinserttheofficerlocationandstatusintothexmldatafile//Ireadabouthowtodothisathttp://prathapk.net/creating-wcf-service-to-store-read-data-in-xml-database///andhttps://msdn.microsoft.com/en-us

C# 使用 linq 查找匹配两个元素级别的 xml 元素

我正在尝试从xml文档中选择一个XElement并匹配xml文档的两个“级别”。我的文件结构是:......我想在图书馆“Main”中找到名为“test2”的阅读列表,这样我就可以将这个元素和所有子元素复制到另一个图书馆节点。我更喜欢使用linq的解决方案,因为我正在尝试学习它。在此先感谢您的帮助当我添加一个新的“阅读列表”时,我是这样做的:publicvoidAddReadingList(stringfullyQualifiedPath,Librarylib,stringname){XDocumentxdoc=XDocument.Load(fullyQualifiedPath);XE

c# - JSON 到 XML 类转换

我似乎无法将Json的类排列到LinqXML中。c.first、c.second和c.third突出显示并声明:"Areyoumissingausingdirectiveorassemblyreference."varserializer=newJavaScriptSerializer();varjson1="[count:[place:{first:1,second:2,third:3}],[place:{first:11,second:22,third:33}],[place:{first:111,second:222,third:333}]]]";varjsons=seriali