linq-to-xml

How to read from xml file without /n/t/t myValue \n\t\t

Im reading from a xml and my values seem to come all right except with \n\t\t wrapping them... presumably something to do with spacing and stuff... how do i tell C# to ignore this? ...

Linq to XML, where value is null

Hello, I have some problem with my code public IQueryable<PageItems> GetPageById(Guid Id) { var xml = Utility.LoadXmlFile("Pages/" + Id); var q = (from f in xml.Descendants("Page") where (Guid)f.Element("id") == Id select new PageItems { Title = f.Element("Title").Value, ...

Get a string from xml files

Hello i have a coode that are trying to get the id of xml file where url exist. My code public static string GetPageIdByUrl(string url) { string folder = HttpContext.Current.Server.MapPath("/App_Data/Pages/" + Path.DirectorySeparatorChar); foreach (string file in Directory.GetFiles(folder, "*.xml", SearchOption.TopDirector...

Can someone help with this generic extension method?

I'm trying to convert an XElement to either null or whatever type T is supplied. Here's what I have so far: public static T? ConvertToNullable<T>(this XElement element) where T : IConvertible { if (element.IsNill()) return null; else return (T)element; } Error: The type T must be a non-nullable value type ...

LINQ to XML getting value

This is a newbie question but I cant seem to find to do the following: XML is this - <sets><set><title>hello1</title><images><image>1667</image></images></set></sets> foreach (XElement setNode in collectionXML.DescendantNodes()) { myString = setNode.Descendants("title").First().... } From First(), how do i get t...

Grouping and summing in Linq to XML

Be most grateful if someone could help with this. Given the XML below, I need to group by InputItem and sum the costs for all years. So the results should be Research Contracts, 7000 Technical Contracts, 5000 Hospitality, 2000 Here's the XML: <Inputs> <Inputs_Table_Row> <InputItem>Research Contracts</InputItem> <TotalYear1>100...

sorting xml file with linq

Hello :) I would like to sort my xml for which the inffered schema is placed below. I would like to sort rows based on one column value (alphabetical) Is it possible to do that in Linq to Xml? Or XSLT is my only option? Thanks Kamil Ok, I removed schema and provide part of file <Matrix> ... <Rows> <Row> ...

extracting RDL data using LINQ

I'm working with some SQL Report definition files (RDLs), using LINQ to extract component query statements for validation. I'm trying to extract the <DataSet> elements from under the <DataSets> element. I seem to be getting hung up with one of the elements under <DataSet><Fields><Field> which has a namespace qualifier <rd:TypeName> I've...

RSS Feed Trouble w/ Linq

Trying to read an RSS and select information using Linq but can't seem to get it working. Here is my code: XDocument feedXML = XDocument.Load( "http://eventful.com/atom/performers/bliminal-/P0-001-000192452-0"); var feeds = from feed in feedXML.Descendants("entry") select new { ...

How to produce multiple items in Linq to XML enumerator?

I have a pretty simple Linq to XML query: var q = from c in xd.Descendants("PrimaryCategory") where (int)xd.Element("PrimaryCategoryID") == 3 select new {campaignName = c.Element("CategoryList").Element("CategoryName").Value, campaignURL = c.Element("CategoryList").Element("CategoryURL").Value}; This does fine ...

LINQ-to-XML: Selecting specific node value

<PKT> <Result Name="GetBalance" Success="1"> <Returnset> <Balance Type="int" Value="0" /> </Returnset> </Result> </PKT> Best way to get the value of Balance with LINQ-to-XML? ...

LinqToXML, breaking when Node doesn't exist. How do I check for existence?

var doc = XDocument.Parse(inputXML); this bombs out when "amount" node is not present. How can I check for existence prior to evaluating? decimal amt; var amount = doc.Descendants("amount").SingleOrDefault().Value; bool amountValid = decimal.TryParse(amount, out amt); I need to make sure "amount" is available prior to evaluating....

Unexpected exception from XDocument constructor

This works fine: XDocument xdoc = new XDocument( new XDeclaration("1.1", "UTF-8", "yes"), new XProcessingInstruction("foo", "bar"), new XElement("test")); But if I change it to pass the "params array" explicitly as an array, it fails with this System.ArgumentException: Non white space characters cannot be ...

Is it just me? I find LINQ to XML to be sort of cumbersome, compared to XPath.

I am a C# programmer, so I don't get to take advantage of the cool XML syntax in VB. Dim itemList1 = From item In rss.<rss>.<channel>.<item> _ Where item.<description>.Value.Contains("LINQ") Or _ item.<title>.Value.Contains("LINQ") Using C#, I find XPath to be easier to think about, easier to code...

LINQ-to-List and IEnumerable issues

I am querying an HTML file with LINQ-to-XML. It looks something like this: <html> <body> <div class="Players"> <div class="role">Goalies</div> <div class="name">John Smith</div> <div class="name">Shawn Xie</div> <div class="role">Right Wings</div> <div class="name">Jack Davis</div> ...

LINQ to XML or SQL Server 2005 XML DML?

I'm writing an app that retrieves RSS feeds on a scheduled daily basis and saves the contents of each feed as XML Data in a SQL Server 2005 database. I want to display the aggregated items, sorted by date, for example, from the saved feed data in my app in Asp.Net GridViews. My question is: should I use LINQ to XML to query the feed da...

LINQ to XML Newbie Question: Reading xml and order by attribute

I have a noob LINQ to XML question. I have xml like so: <pages> <page Name="Welcome" Control="Welcome" Order="1"></page> <page Name="Summary" Control="Summary" Order="10"></page> </pages> I need to read in the data and save it to an array ordered by the "Order" attribute. Here's what I have; the compiler is coughing on...

Compare two xml and print the difference using LINQ

I am comparing two xml and I have to print the difference. How can I achieve this using LINQ. I know I can use XML diff patch by Microsoft but I prefer to use LINQ . If you have any other idea I will implement that //First Xml <Books> <book> <id="20504" image="C01" name="C# in Depth"> </book> <book> <id="20505" image="C02...

How can i use "like" in linq to xml

I wanna do something like this. I know it’s wrong: var a = from h in xdoc.Root.Elements() where h.Element().value like = "1234" select h; ...

need links to xml concepts for asp.net 3.5 web app development

Hi, We are developing a project using asp.net 3.5 and sql server 2008. I know a bit of xml like creating, loading, adding elements to xml file. I was not exposed to XML Scema, XSLT and XPath kind of stuff. And now there is LINQ to XML and LINQ to SQL also. Could anyone please provide me some good links to learn complete XML for using...