linq-to-xml

How to access a specific attribute using LINQ to XML

时光毁灭记忆、已成空白 提交于 2019-12-12 04:43:01
问题 I wish to access some specific attribute (Tag name) i an XML file, and place them in a list but i cant get i right. What am I doing wrong?? The list should look like this: Tag_1 Tag_2 Tag_3 Code: XElement xelement = XElement.Load("C:/...../Desktop/Testxml.xml"); var tagNames = from tag in xelement.Elements("tagGroup") select tag.Attribute("name").Value; foreach (XElement xEle in tagNames) { //.... } Here is the XML file: <configuration> <logGroup> <group name="cpm Log 1h 1y Avg" logInterval="

Binding results of an linq to xml query to the same gridview

☆樱花仙子☆ 提交于 2019-12-12 04:38:39
问题 How can I bind the results of my linq to xml query parser to the same gridview. I'm only able to see the last one for the ZAxisCalib/query3. string[] fileEntries = Directory.GetFiles(@"c:\Sciclone UAC", "*.cfg*"); foreach (string fileName in fileEntries) { XDocument doc = XDocument.Load(fileName); var query = from x in doc.Descendants("XAxisCalib") select new { MaxChild = x.Descendants("Max"), MinChild = x.Descendants("Min") }; { var bs1 = new BindingSource { DataSource = query };

Getting data from xml by attribute vlaue

守給你的承諾、 提交于 2019-12-12 04:08:52
问题 I have a file with the following content (myfile.xml). I have to get all content coming under (including product node) a product with id=1 . <products> <product id="1"> <category>q</category> </product> <product id="2"> <category>w</category> </product> <product id="3"> <category>e</category> </product> </products>` i.e. the result should be : <product id="1"> <category>q</category> </product> How can I do this? 回答1: var root = XElement.Load("path to the file"); var node = root.Descendants(

Spacing out output with Linq to Xml

本秂侑毒 提交于 2019-12-12 04:06:28
问题 How is it possible to force extra spacing between some nodes using Linq to Xml? I am looking to output the following: <root> <group> <leaf /> </group> <group> <leaf /> </group> </root> By adding Empty XText, it only destroys the formatting. var root = new XElement("root", new XText(""), new XElement("group", new XElement("leaf")), new XText(""), new XElement("group", new XElement("leaf")), new XText("")); Console.WriteLine(root.ToString()); resulting in <root><group><child /></group><group>

Accessing nested elements while iterating an XML LINQ query?

故事扮演 提交于 2019-12-12 03:46:00
问题 With this XML data: <item> <placemarks> <placemark> <uid>{EA5FA2B2-78CB-4FAA-9F17-EBB361410499}</uid> </placemark> </placemarks> <links> <link> <title>Book Online</title> <link>https://blah</link> </link> <link> <title>Call to Book</title> <link>tel:1-866-555-5555</link> </link> </links> </item> I'm trying to create Hotel objects w/ various attributes from the XML. Everything works fine until I hit nested XML tags and then I got stuck: var items = root.Descendants ("item"); var hotels = from

Displaying results of a LINQ TO XML query in Gridview

£可爱£侵袭症+ 提交于 2019-12-12 03:41:30
问题 I am querying an xml document in LINQ and would want to display the results in gridview to allow users to select from the list. the query is as a result of user input. Here's a copy of my xml. <?xml version="1.0" standalone="yes"?> <NewDataSet> <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop"> <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata

How to combine multiple nodes into one from a ATOM feed

眉间皱痕 提交于 2019-12-12 03:27:41
问题 theResult XDocument: <?xml version="1.0" encoding="UTF-8"?> <feed xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xml:base="http://mysharepointhomesite/_api/"> <id>ecfe572e-051e-4d49-899e-1c025wersfd7d</id> <title /> <updated>2017-03-20T14:13:12Z</updated> <entry m:etag="&quot;1&quot;">

Get XML Node Data

南楼画角 提交于 2019-12-12 03:14:31
问题 I am new to XML and am trying to get some of the information from this XML document: http://pastebin.com/S7eUNmL2 Using this code: Dim Document As New XmlDocument Document.LoadXml(xml) Dim DocumentElement As XmlElement = Document.DocumentElement Dim ResourceSets As XmlNode = DocumentElement.ChildNodes.ItemOf(6) Dim ResourceSet As XmlNode = ResourceSets.ChildNodes(0) Dim Resource As XmlNode = ResourceSet.ChildNodes(1) Dim LocationList As XmlNodeList = Resource.ChildNodes Dim Location As

LINQ TO XML Update WIX PATCH File

风格不统一 提交于 2019-12-12 03:13:50
问题 Give the following XML I'm trying to update the UpgradeImage and TargetImage SourceFile attributes respectively using Linq to XML. Is there an issue with the way this XML is formed or am I just completely missing something? <?xml version="1.0" encoding="utf-8"?> <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> <PatchCreation Id="224C316C-5894-4771-BABF-21A3AC1F75FF" CleanWorkingFolder="yes" OutputPath="patch.pcp" WholeFilesOnly="yes"> <PatchInformation Description="Update Patch"

Linq to XML, how to acess an element in C#?

拜拜、爱过 提交于 2019-12-12 03:05:22
问题 Here is my XML I need to parse: <root> <photo>/filesphoto.jpg</photo> <photo:mtime>12</photo:mtime> <text>some text</text> </root> To access the <text> element I use this code: var doc = XDocument.Parse(xml.Text); doc.Descendants("text").FirstOrDefault().Value; How can I access <photo:mtime> ? 回答1: The element mtime is in the namespace that is mapped to photo . You can access it as follows: var doc = XDocument.Parse(xml.Text); XNamespace ns = "your nanespace URI goes here" doc.Descendants(ns