linq-to-xml

Is this valid xml for reading using linq to xml

hi i have a confusion about xml please tell me is this valid xml or not. i want to read it using linq to xml <registeredPeople> <id>1</id> <name>mohsan</name> <id>2</id> <name>ali</name> <id>3</id> <name>azhar</name> </registeredPeople> ...

Location of XElement when querying over IEnumerable using LINQ

I have a linq query that is querying over IEnumberable. When I have a matching element for my where clause I would like to know the position of the element in the IEnumberable. var result = from e in elements where (string) e.Attribute("class") == "something" select e.Position(); The e.Position() of course do...

unable to edit DataGridView populated with results of LINQ query

When i use the results of a linq-to-xml query to populate a datagridview, i cannot edit the datagridview. i've tried setting the datagridview's readonly property to false and that doesn't help. I also added an event handler for cellBeginEdit and put a breakpoint there, but it doesn't get hit. Any idea what i'm doing wrong, or if this ...

parsing xml file with f# linq to xml

F# newbie I have 2 xml files in 2 folders c:\root\a\file.xml and c:\root\b\file.xml They have identical structure <parent> <property name="firstName">Jane</property> <property name="lastName">...</property> <property name="dateOfBirth">...</property>> </parent> I need to chose the file which property node with name "firstNa...

How do i get all "properties" from xml via linq to xml

XML sample (original link): <records> <record index="1"> <property name="Username">Sven</property> <property name="Domain">infinity2</property> <property name="LastLogon">12/15/2009</property> </record> <record index="2"> <property name="Username">Josephine</property> <property name="Domain">infinity3</property...

Passing in a different datatype into a method that expects a different datatype

Hi, With the XElement class, its constructor clearly takes the daya type XName as its first parameter, however, if I pass in a string, it works and I don't get a compile time error. What's going on here exactly and how can I implment this in my own code? Thank you, ...

LINQ to XML: suppressing redundant namespace attribute in child nodes

If a node belongs to a namespace, it's children by default belong to the same namespace. So there's no need to provide an xmlns attribute on each child, which is good. However. If I create two nodes like this: Dim parent = <parent xmlns="http://my.namespace.org"/&gt; Dim child = <child xmlns="http://my.namespace.org"&gt;value&lt;/chil...

Understanding Linq To Xml - Descendants return no results

Hi, I'm a completly New to Linq2XML as I code to much lines to perform simple things, and in a simple project I wanted to give it a try... I'm with this for 2 hours and nothing I do get's it right :( I'm really, really thinking to go back to XmlNode-code-alike The Task: I send a SOAP Action to an ASMX service and I get the response...

Use Linq to Xml with Xml namespaces

Hi all, I have this code : /*string theXml = @"<Response xmlns=""http://myvalue.com""&gt;&lt;Result xmlns:a=""http://schemas.datacontract.org/2004/07/My.Namespace"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""&gt;&lt;a:TheBool&gt;true&lt;/a:TheBool&gt;&lt;a:TheId&gt;1&lt;/a:TheId&gt;&lt;/Result&gt;&lt;/Response&gt;";*/ string...

Strange result with string comparison in LINQ

I have a XML source with nodes like this (Somewhat anonymized): <XXX> <Code A="oa ">01</Code> <Name A="oa ">Card</Name> <F1 A="oa ">x</F1> <F2 A="oa ">y</F2> <F3 A="oa ">z</F3> </XXX> I load the XML-document into a XElement and query it with linq var query = from creditcard in xml.Descend...

Nice way to do linq to xml multilevel "element" query without having to check for null

I'm working with an xml fragment, and finding that I'm doing the following a lot: dim x = xe.Element("foo").Element("bar").Element("Hello").Element("World").Value however I can't always guarantee that the xml document will contain foo or bar. Is there a nicer way to do this sort of thing without having to null check every query? i.e....

How to make this LINQ to XML query more elegant?

I have a collection of MODS records that looks like this: <modsCollection> <mods [namespaces etc] > <genre authority="diva" type="contentType" lang="eng">Other academic</genre> <genre authority="diva" type="contentType" lang="swe">Övrigt vetenskapligt</genre> <name type="personal"> <namePart type="family">Svensson</nam...

How do you create an indented XML string from an XDocument in c#?

I have an XDocument object and the ToString() method returns XML without any indentation. How do I create a string from this containing indented XML? edit: I'm asking how to create an in memory string rather than writing out to a file. edit: Looks like I accidentally asked a trick question here... ToString() does return indented XML. ...

Can I rewrite this LINQ to XML better?

I'm just learning LINQ and in particular LINQ to XML, and I've written up a query that works but I'm wondering if I'm doing it a bit round-a-bout. Can the code be improved? I have an XDocument: <SomeDocument> <Prop1> val1 </Prop1> <Prop2> val2 </Prop2> <Prop3> val3 </Prop3> </SomeDocument> But Prop1, Prop2, and Prop3 ma...

Problem with linq to xml

Hello - I am probably missing something obvious, but I am getting a 'Object reference not set to an instance of an object' null error in my Linq to xml query. Here is a sample of the xml <airport> <station> <city>Rutland</city> <state>VT</state> <country>US</country> <icao>KRUT</icao> <lat>43.52999878</lat> <lon>-72.94999...

Get the Count of Elements where candidate has won

LINQ2Xml: I would like to get the count of elements where candidate has won in every province. I need some help. <Pronvice_Data> <Pronvice>PronviceA</Pronvice> <Registered_Voters>115852</Registered_Voters> <Sam_Kea>100</Sam_Kea> <Jeje>500</Jeje> <John_Doe>400</John_Doe> </Pronvice_Data> <Pronvice_Data> <Pronvice...

Linq2XML: Get the count of elements where candidate has won2

I had an XML Document in the format below <Pronvice_Data> <Pronvice>PronviceA</Pronvice> <Registered_Voters>115852</Registered_Voters> <Sam_Kea>100</Sam_Kea> <Jeje>500</Jeje> <John_Doe>400</John_Doe> </Pronvice_Data> <Pronvice_Data> <Pronvice>PronviceA</Pronvice> <Registered_Voters>25852</Registered_Voters> ...

Add elements to XDocument after LINQ Query

I have the following XML LINQ query from my XDocument. var totals = (from x in MyDocument.Descendants("TOTALS") select x).FirstOrDefault(); Once I have found my totals node I need to add some elements to that node and push that change to the XDocument. ...

What is the difference between these 2 XML LINQ Queries?

I have the 2 following LINQ queries and I haven't quite got my head around LINQ so what is the difference between the 2 approaches below? Is there a circumstance where one approach is better than another? ChequeDocument.Descendants("ERRORS").Where(x=>(string)x.Attribute("D") == "").Count(); (from x in ChequeDocument.Descendant...

LINQ to XML query returning a list of all child elements

I have got an XML document which looks something like this. <Root> <Info>....</Info> <Info>....</Info> <response>....</response> <warning>....</warning> <Info>....</Info> </Root> How can i write a LINQ to XML query so that it returns me an IEnumerable containing each child element, in this case all five child elements of , so that i c...