xdocument

Why isn't this XElement query working on my xml

My xml looks like: <nodes> <node name="somekey"> <item name="subject">blah</item> <item name="body">body</item> </node> </nodes> And my code so far is: XDocument doc = XDocument.Load(HttpContext.Current.Server.MapPath(String.Format("~/files/{0}/text.xml", "en"))); if (doc != null) { XElement element = doc.Elements().Where(e => e...

How do you extract a specific element out of an XDocument?

I have the following XDocument: <SomeDoc Id="73" Protocol="rahrah" xmlns="http://schemas.company.com/rah/rah2/2005/"&gt; <Prop1>11111</Prop1> <Prop2>77777</Prop2> <Prop3>88888</Prop3> </SomeDoc> And I want to extract the value in Prop1. I use the following code: var prop1 = xml.Element("Prop1"); But prop1 is being set to ...

problem writing xml to file with .net mvc - timeout?

Hey, so having an issue with writing out to an xml file. Works fine for single requests via the browser, but when I use something like Charles to perform 5-10 repeated requests concurrently several of them will fail. The trace simply shows a 500 error with no content inside, basically I think they start timing out waiting for write acces...

XDocument unable to digest url in header if encountered twice

Hi there, I am consuming an xml response from a government gateway which contains a url in its root node twice (being firstly xsi:schemaLocation="http://www.govtalk.gov.uk/CM/envelope" and also xmlns="http://www.govtalk.gov.uk/CM/envelope") XDocument will only parse this if I pull out the second one (the xmlns one) from the node. Is ...

XDocument Attribute Performance Concerns

I have a loaded XDocument that I need to grab all the attributes that equal a certain value and is of a certain element efficiently. My current IEnumerable<XElement> vm; if (!cacher2.TryGetValue(name,out vm)) { vm = project.Descendants(XName.Get(name)); cacher2.Add(name, vm); } XElement[] abdl = (vm.Where(a => a.Attribute(at...

How do I get a list of child elements from XDocument object?

Hello.. I am trying to get all of the "video" elements and their attributes from an XML file that looks like this: <?xml version="1.0" encoding="utf-8" ?> <videos> <video title="video1" path="videos\video1.wma"/> <video title="video2" path="videos\video2.wma"/> <video title="video3" path="videos\video3.wma"/> </videos> The foll...

How can I easily get a TextReader from an XDocument?

Given an XDocument instance, how can I easily get a TextReader that represents that instance? The best I've been able to come up with is something like this (where xml is an XDocument instance): var s = new MemoryStream(); var sw = new StreamWriter(s); xml.Save(sw); sw.Flush(); s.Position = 0; TextReader tr = new StreamReader(s); ...

Noob LINQ - reading, filtering XML with XDocument

I'm just learning XDocument and LINQ queries. Here's some simple XML (which doesn't look formatted exactly right in this forum in my browser, but you get the idea . . .) <?xml version="1.0" encoding="utf-8"?> <quiz xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.com/name XMLFile2.xsd"...

XDocument change all attribute names

I have an XDocument that looks similar to <root> <a> <b foo="1" bar="2" /> <b foo="3" bar="4" /> <b foo="5" bar="6" /> <b foo="7" bar="8" /> <b foo="9" bar="10" /> </a> </root> I wish to change the attribute foo to something else, and the attribute bar to something else. How...

Silverlight recursivly bind Treeview to XDocument

How can I recursivly bind a Treeview to an XDocument, mapping each XML Element to a Node in the Treeview? The code below should work from my perspective (and also according to the very few posts I found regarding direct binding), however it does not: <sdk:TreeView ItemsSource="{Binding Path=Elements}" DataContext="{Binding Path=Data}">...

Is there a way to use a dictionary or xml in the Application Settings?

I have to store a complex type in the application settings. I thought that storing it as XML would work best. The problem is I don't know how store XML. I prefer to store it as a managed XML rather than using just a string of raw XML having to parse it on each access. I managed to set the Type column of the setting to XDocument, but I w...

Find Elements by Attribute using XDocument

This query seems to be valid, but I have 0 results. IEnumerable<XElement> users = (from el in XMLDoc.Elements("Users") where (string)el.Attribute("GUID") == userGUID.ToString() select el); My XML is as follows: <?xml version="1.0" encoding="utf-8" standalone="yes"?> <Users> <User GUID="68327fe2...

Loading not-so-well-formed XML into XDocument (multiple DTD)

I have got a problem handling data which is almost well-formed XHTML document except for it has multiple DTD declarations in the beginning: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <!DOCTYPE HTML PUBLIC "-//W3C...

Manually iterating over a selection of XML elements (C#, XDocument)

What is the “best practice” way of manually iterating (i.e., one at a time with a “next” button) over a set of XElements in my XDocument? Say I select the set of elements I want thusly: var elems = from XElement el in m_xDoc.Descendants() where (el.Name.LocalName.ToString() == "q_a") select el; I can use an...

Databinding question: DataGridView <=> XDocument (using LINQ-to-XML)

Learning LINQ has been a lot of fun so far, but despite reading a couple books and a bunch of online resources on the topic, I still feel like a total n00b. Recently, I just learned that if my query returns an Anonymous type, the DataGridView I'm populating will be ReadOnly (because, apparently Anonymous types are ReadOnly.) Right now, ...

.NET: XDocument missing XDeclaration?

When I write out this to the console, the output is missing the XDeclaration content. What gives? var map = new XDocument( new XDeclaration("1.0", "UTF-8", null), new XElement(SiteMap.Namespace + "urlset") ); Console.Write(map.ToString()); How do I get the XML for map including the <?xm...

Parsing XML stream in ASP.NET 3.5

Hi All, I am trying to build an ASP.NET 3.5 application based on XML streams from a legacy systems. My issue is once I get the XML I have to built menus and sub menus from the XML as well filter data(XML stream) based on the menu selection without making roundtrip to the Data store(legacy system). Right now I have a DAL which will get ...

XML file creation Using XDocument in C#

i've a list (List< string>) "sampleList" which contains Data1 Data2 Data3... How to create an XML file using XDocument by iterating the items in the list in c sharp. The file structure is like <file> <name filename="sample"/> <date modified =" "/> <info> <data value="Data1"/> <data value="Data2"/> <data ...

loading an xml in web apps directory from a library dll

my web application has an xml file here: /files/xml/test.xml I need to load a XDocument from within a class library project, how will I reference the xml? I don't want to pass any path parameters to this method. I want to assume the location is fixed at /files/xml/test.xml. How can I load a XDocument know this? I don't seem to hav...

How set timeout on XDocument.Load(string uri)?

Is there a way to set a timeout on System.Linq.Xml.XDocument.Load(string uri)? Or should I use the technique described in http://stackoverflow.com/questions/299198/implement-c-generic-timeout? ...