linq-to-xml

Adding Xelement as a Sibling of Xelement without a Parent

I'm trying figure out if this is possible. Basically, I need to create an XElement and then add one or more siblings to that XElement, but without a parent. I'll add that list of XElements to a Parent later, but need some flexibility in building this and other lists of XElements before doing so. Is this possible? So I would have somethi...

LinqXML Filter through attribute - beginner

Hi I have got below XML document <Documents Databasename="Type1"> <Document> <Documentnumber>xxxxxx</Documentnumber> <Documentname>xxxxxx</Documentname> <DocumentExtension>xxxxxx</DocumentExtension> <ImportAction>xxxxxx</ImportAction> <Authorname>xxxxxx</Authorname> <Practicegroup>xxxxxx</Practicegroup> <Createddate>xx...

Populate a class from Linq to XML

Ok, so I have an XML file that pretty much looks like this: <Templates> <Template> <TemplateID>00X500000011iTSEAY</TemplateID> <To> <To type='User'>00550000000mfOU</To> <To type='User'>00550000000mb3pAAA</To> <To type='Group'>00G50000001PiHz</To> <To type='AccountTeam'...

How can i check if this XElement is not null before adding it to an anonymous object?

I'm populating an anonymous object from an XML file. Up until now, commentary.Elements("Commentator") has always had a value so i've never had to check for null. I've had to remove that though, and now it's failing when it tries to read that line. I'm looking at the code and I don't know what to change though, because its being selec...

Is there a way to get the original HTTP response string from a WebException?

I have a web app which talks to a custom back-end server over HTTP. The server provides its responses in XML and I use Linq-to-XML to parse the results. If the server cannot process a query it will send back a 400 bad request header which includes detailed information about the problem. i.e. HTTP/1.1 400 Bad Request (invalid query)...

C# winform treeview control to search xml

Can someone help me with a code snippet in C# to search(linq preferably) for either XML element or attribute in a XML loaded using treeview control? The user has a search string tab in a WinForm UI and on a successful search the given node containing the element or attribute string is highlighted. ...

Querying multiple XML files with LINQ in C# Statements

I'm attempting to extract data from a number of XML files posted on the Internet using LINQ. I'm working with LINQPad and using C# Statements. All files have the same format and Element names. My goal is to extract the same Elements from each file and then report the elements in one row per file, creating a grid of sorts. This would then...

LINQ to XML - Selecting elements based on values that exist in other elements

I guess I'm pushing the boundaries of whats capable with LINQ to XML but I'd like to select a group of elements that contain values that match a value contained in another element node. In the XML below I want to select only the "Option" elements that contain values that are also contained in the AvailableOptions" element for a specifi...

Extract some Elements with LinqToXML from GPX-File for Geocaching

Hi, i'm trying to get some Elements from a gpx-file (is a xml file). This is not the standard gpx-scheme. There are some changes from geocaching.com which is a website for geocaching. My sample XML-File lookslike this: <?xml version="1.0" encoding="utf-8"?><gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http:...

Updating Child's Attribute of a XElement (or a Cloned XElement)

Hello...I have an XML as follows. <AFConfig> <Geographies> <Geography id="Place1" description="NicePlace"> <MetaData> <Services> <Service> ... ... </Service> </Services> </MetaData> <Systems> <DefaultSystem systemName="SYSONE" server=http"//192.168.0.0" /> </Systems> </Geography> <Geogr...

Linq to XML simple get attribute from node statement

Ok so heres the code snippet. XDocument themes = XDocument.Load(HttpContext.Current.Server.MapPath("~/Models/Themes.xml")); string result = ""; var childType = from t in themes.Descendants() where t.Attribute("name").Value.Equals(theme) select ne...

XDocument: Conditionally create new XElement...

Hi all, My question is regarding conditionally creation of XElements, that is, if some condition is met, create the XElement, if not, skip creating the XElement? At this point of time, I could create empty XElements, and then remove all empty elements, by checking, if IsEmpty is true, but that somehow does not feel right... I feel, tha...

Linq to XML adding to List Problem send to repeater.

I need to get data from a XML file from Node1>Node2 Filter data to group from the xml by X Node where X node is equals A,Y,Z.. Group all elements with same X Node value ordered by date Store first element of the group(as ordered by date would be by the latest), and the rest in a subgroup of the same object. If in the filter fails to ...

How do you bind to Xml in SilverLight/Windows Phone?

I am trying to use Linq to Xml and Xaml data binding in a Windows Phone app with no luck, following this example. I've got some Xaml that looks like this: <Image Source="{Binding Path=Element[image].Value, Converter={StaticResource UriBitmapConverter}}" Grid.Column="2" MaxWidth="75" HorizontalAlignment="Righ...

How do I write a Lambda statement for this Linq to XML function?

I am working with this XSD file. The portion of the XML that is relevant to this question is here: <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="https://wsmrc2vger.wsmr.army.mil/rcc/manuals/106-11" targetNamespace="https://wsmrc2vger.wsmr.army.mil/rcc/manuals/106-11" ...

LINQ to XML and DataGridView

Hi I’m trying to use a DataGridView for the first time and with LINQ. Here’s what I’m trying to do: I want to use it (although it doesn’t have to the DataGridView ) to read and display the contents of an XML file (this bit is working code below) but I want to have an add row button on the form or in the DataGridView that takes the conte...

Any way to strip namespace garbage from XML file?

I need to select some nodes from an XML file (AppNamespace.xaml from a Silverlight XAP file, not that it matters), but the file has namespace stuff so XPath doesn't work. I could waste most of a day trial-and-erroring the bondage-and-discipline nightmare of XmlNamespaceManager and end up with hopelessly fragile code that can't tolerate t...

Preserve certain nodes when using LINQ to XML

I am having difficulty preserving certain nodes (in this case <b>) when parsing XML with LINQ to XML. I first grab a node with the following LINQ query... IEnumerable<XElement> node = from el in _theData.Descendants("msDict") select el; Which returns the following XML (as the first XElement)... <msDict lexid="m_en_us0000002.001" type=...

Linq read XML doc with missing nodes

Hi I want to read an XML document but it may have some of the node missing and if so I want to use a defualt value for the missing nodes. XDocument xmlDoc = XDocument.Load(Path.Combine(Application.StartupPath, "queues.xml")); var q = from c in xmlDoc.Root.Descendants("Queue") select new Queue {...

Problem with retrieving data from xml by linq

I have xml from I want get some data XDocument loaded = XDocument.Load(@"c:\TERC.xml"); var query = (from c in loaded.Descendants("catalog") from r in c.Descendants("row") select (string)r.Element("Name")); this returns me collection of null How can I fix it ? Here is this xml: <?xml vers...