草庐IT

LINQ_ENABLED

全部标签

c# - 通过System.Linq在C#中获取元素的属性名称和值

我有一个自定义配置文件。我是通过IConfigurationHandler接口(interface)实现来读取这个文件的。当我读取Detail元素的childNode属性时。它将下面的结果返回到IDE的立即窗口中。elem.Attributes.ToObjectArray(){object[2]}[0]:{Attribute,Name="key",Value="Main"}[1]:{Attribute,Name="value",Value="web"}当我尝试在控制台上书写时Console.WriteLine("Value'{0}'",elem.Attributes.ToObjectA

c# - 如何查询xsi :type from an attribute using Linq to XML?

给定这个xml:100100我想循环组件并根据xsi:type属性实例化每个对象。这是一些LinqtoXML代码:IEnumerablecomponents=fromcinelementsFromFile.Descendants("component")select(XElement)c;foreach(XElementeincomponents){vartype=e.Attributes("xsi:type");}不幸的是,“vartype=e.Attributes("xsi:type");”这一行不起作用,因为名称中不允许使用冒号。知道如何查询每个元素的xsi:type属性吗?谢谢

xml - 将 System.Xml.Linq 与单声道命令行编译器一起使用

在C#/Mono中使用以下代码,usingSystem.Xml.Linq;我遇到了这个错误。errorCS0234:Thetypeornamespacename`Linq'doesnotexistinthenamespace`System.Xml'.Areyoumissinganassemblyreference?WhatassemblyreferencedoIneedtouseSystem.Xml.Linqwithmono?dmcs/r:????main.cs 最佳答案 那就是:dmcs-r:System.Xml.Linq.dll

c# - 使用linq读取xml文件

我有以下xml文件JohnSmith23.05.20113322.06.201129我想使用linq来提取用户名是“JohnSmith”的日期和测试点。我将如何构建我的linq?我已经完成了以下操作,但没有按照我的意愿工作:XElementmain=XElement.Load(@"users.xml");stringt="JohnSmith";varv=fromuserinmain.Elements("User")wheret==users.Element("Name").Valueselectusers;MessageBox.Show(v.First().Element("Date"

.net - 在 Linq 中将样式表引用添加到 XML 文档?

我创建了一个XML文档并希望有一个对XSLT文件的引用。//对于这一代XML:XElementxml=newXElement("ReportedOn",fromdlinEL.DocumentLog.ToList()joinoinEL.Organizationondl.OrganizationIDequalso.OrganizationIdwheredl.ActionDate>=stDate&dl.ActionDate 最佳答案 添加XProcessingInstruction元素。并且不是针对您的XElement(它可以用作文档但有

xml - VB.NET 中的 LINQ to XML

我基本上是LINQ的新手。我在这里看了很多地方,很困惑。我看过一些示例,这些示例允许我使用LINQ强类型对象,但我并不真正理解它们,因为它们是在C#中,我想这可以让您使用LINQ做不同的事情(我认为?)。无论如何,这就是我想要做的:DimproductXMLAsXDocument=XDocument.Load(_Server.MapPath("~/App_Data/products.xml"))DimproductsAsList(OfProduct)='somequerytoselectallproducts?''setupProductpropertieshere'someProdu

xml - 使用 Linq to XML 检查 XML 子元素是否存在

我正在努力解决我在LinqtoXML中遇到的问题,看起来应该很简单,但即使在此处浏览了LinqtoXML问题之后,我还是不太明白。按照以下XML行进行操作:我现在想检查ID为2的用户是否有电话号码。有人可以提出一个解决方案吗,就像我说的那样,应该很简单......干杯,奥拉 最佳答案 这是一种查询方法:XElementyourDoc=XElement.Load("yourfilename.xml");boolhasPhone=(fromuserinyourDoc.Descendants("user")where(int)user.A

c# - 使用 linq 将数据添加到现有的 xml 文件

我是.net初学者。我需要向xml文件中添加一些数据xml文件是:---1stlevel/*idontwanttocreatethisbecausethisexists*/--2ndlevelToothpasteColgate1210ToothpastePepsodent2012我需要添加productname-->Toothpastebrandname-->CloseUpquantity-->16price-->15到他们各自的标签。我现在面临的问题是我需要深入两层来写入它们各自的标签,我不知道该怎么做。我试过下面的代码:(不工作)XDocumentdoc=newXDocument(

xml - 如何在 PowerShell 中编写 Xml.linq?

我正尝试在PowerShell中执行此操作:XDocumentdocument=XDocument.Load(@"web.config");varcomments=document.Descendants("client").DescendantNodes().OfType().ToArray();foreach(varcommentincomments){XElementunCommented=XElement.Parse(comment.Value);comment.ReplaceWith(unCommented);}我试过这样的:$xDoc=[System.Xml.Linq.XD

C# - 使用 Linq 选择 XML 后代

我有以下XML结构:11ת"א24אבטליון我想用Linq遍历name节点。我试过这个:varitems=(fromiindoc.Descendants("row")selectnew{Text=i.Value}).ToList();但它没有按照我需要的方式工作。有什么建议吗? 最佳答案 varitems=doc.Descendants("field").Where(node=>(string)node.Attribute("name")=="Name").Select(node=>node.Value.ToStrin