草庐IT

dynamic-linq

全部标签

c# - Linq to XML 查询

假设我有一个如下所示的XML文件:使用Linq是否有可能做这样的事情:?foreachcustomerinCustomersselectWeaponPurchasedwhereNameequals"JasonVoorhees"或:foreachcustomerinCustomersselectcustomerlabel1.Text+="Name:"+customer.Name+Environment.NewLine+"WeaponPurchased:"+customer.WeaponPurchased;我以前在MSDN上见过这种类型的查询,但我收藏夹中的链接现在指向错误的页面,我仍在努

c# - 使用 linq 与 xmlDocument 从 XML 字符串中提取数据

我已经使用xmlDocument方法多次完成以下操作,但我想使用更强大的linqtoxml方法。然而,我似乎碰壁了。我正在从twillio/crmText的restfulAPI获取数据。这是他们的文档所在站点的链接:http://crmtext.com/api/docs这是我的XML字符串:390082812015-04-3016:17:19361855512121stChoiceCourier我需要找出optinStatus。它应该返回3。我正在使用下面的,它返回上面的xmlXDocumentxdoc=XDocument.Parse(result1);我已经尝试了大约4000种不同的

c# - 异常 : The XPath expression evaluated to unexpected type System. Xml.Linq.XAttribute

我有一个如下所示的XML文件:Prasad19986730630City1IndiaCity2India现在我想获取所有地址类型。我像下面这样使用XPath进行了尝试,但出现了异常。varxPathString=@"//Employee/Address/@Type";doc.XPathSelectElements(xPathString);//docisXDocument.Load("xmlfilePath")Exception:TheXPathexpressionevaluatedtounexpectedtypeSystem.Xml.Linq.XAttribute.我的XPath有问

c# - 如何使用 XmlWriter 将 System.Xml.Linq.XElement 写入流

我有一个XElement实例,我希望使用XmlWriter类写入流。为什么?好吧,其中一个配置设置定义了是否使用二进制Xml。基于此设置,创建合适的XmlWriter实例-通过XmlWriter.Create(stream)或XmlDictionaryWriter.CreateBinaryWriter(stream))。无论如何,我正在尝试以下代码,但它使流为空:using(varstream=newMemoryStream()){varxmlReader=newXDocument(xml).CreateReader();xmlReader.MoveToContent();varxml

c# - 尝试使用 Linq to XML (C#) 解析 XML 树

我想在我的对象结构中反射(reflect)XML树,但我是LINQtoXML的初学者我有一个具有以下结构的XML:1sometext11sometext11sometext112sometext2sometext22sometext223sometext3sometext33sometext33sometext33sometext333...我有以下类(class):publicclassQuestion{publicstringtext{get;set;}publicIListanwsers=newList();}publicclassAnwser{publicstringconte

xml - 如何按属性值对 LINQ C# 中的 XML 进行排序?还有MVC

(使用最新的MVC2RC2)我正在尝试通过元素的属性值对LINQ(C#)中的一些XML进行排序...varsites=fromsinxDoc.Element("sites").Elements("site")orderbys.Attribute("name")selects;但是当我将它传递给我的View时,我得到了异常:ExceptionDetails:System.ArgumentException:AtleastoneobjectmustimplementIComparable.SourceError:Line37:Line38:Line39:Line41:谁能告诉我如何使用LI

c# - 当子节点存在时,LINQ Xelement 返回 null

我有一个这样的XML文件,我想读取ID、短名称、名称节点值。17406testtest18006ANOTHERtestAnothertest18046RKUhospital18047MNUMNU递归读取Node元素的最佳方法是什么?这就是我尝试读取节点值的方式:varaccountingunit=(fromeinXDocument.Parse(textresult).Root.Elements("AccountingUnit")selectnewnode{idvalue=(string)e.Element("ID"),shortname=(string)e.Element("Short

c# - 选择节点 Linq to Xml C#

XML文件格式:element1daily0.2element2daily0.2我想选择所有“loc”节点(element1、element2),但这不起作用!!!foreach(XElementitemindocument.Elements("url").Descendants("loc"))//Changeintowhat?{urlList.Add(item.Value);} 最佳答案 我怀疑问题是您要从document.Elements("url")而不是document.Root.Elements("url")...所以它正

c# - Visual Studio 2010 是否有使用 LINQ/XPATH 查询 XML 文件的插件?

有一个XML文件。我需要对其进行一些统计(例如,有多少节点没有特定属性等)。我没有看到任何能让我立即做到这一点的东西。有什么建议么?我目前正在为Chrome使用XMLTree插件,但它不仅在VS之外,而且有时对我也不起作用。 最佳答案 找到这个东西:http://visualstudiogallery.msdn.microsoft.com/c5d4671c-2e29-4452-b039-6f931b7b1155/.似乎在做我需要的并很好地集成到VSIDE中。 关于c#-VisualStu

c# - 如何使用 linq to XML 添加/插入条件节点到 XML

我生成了一个这样的xml文件:XElementemployees=newXElement("Work",newXElement("record",newXElement("Name",textBox1.Text),newXElement("Phone","206-555-0144"),newXElement("Address",newXElement("Street1","123MainSt"),newXElement("City","MercerIsland"),newXElement("State","WA"),newXElement("Postal","68042"))),new