Q: WPF: How do I fill a datagrid with NWS XML Data that contains Attributes with spaces using LINQ I am trying to fill a DataGrid with XML data provided by the National Weather services REST service. I am able to get the data but have been having an issue with populating a DataGrid control in my WPF app.
The issue seems to be that the are spaces in the elements that are being returned by the NWS. I am not sure how to proceed. any help would be most appreciated. 
    using System.Linq;
    using System.Windows;
    using System.Net;
    using System.Xml.Linq;

    namespace datagrid
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();

                string requestUrl = "http://www.weather.gov/forecasts/xml/sample_products/browser_interface/ndfdXMLclient.php?lat=47.5055&lon=-111.2831&product=time-series&maxt=maxt&mint=mint&wspd=wspd&wdir=wdir&wgust=wgust";

                WebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;
                WebResponse response = request.GetResponse() as HttpWebResponse;

                var xmlDoc = XDocument.Load(response.GetResponseStream(),LoadOptions.PreserveWhitespace);
                var i = from item in xmlDoc.Descendants("wind-speed")
                        select new
                        {
                            WindSpeed = item.Attribute("Wind Speed").Value
                        };
                dataGrid1.ItemsSource = i.ToList();
            }
        }
    }

when I run the code I get the this exception
System.Xml.XmlException was unhandled by user code
  HResult=-2146232000
  Message=The ' ' character, hexadecimal value 0x20, cannot be included in a name.
  Source=System.Xml
  LineNumber=0
  LinePosition=5
  StackTrace:
       at System.Xml.XmlConvert.VerifyNCName(String name, ExceptionType exceptionType)
       at System.Xml.Linq.XName..ctor(XNamespace ns, String localName)
       at System.Xml.Linq.XNamespace.GetName(String localName)
       at System.Xml.Linq.XName.Get(String expandedName)
       at System.Xml.Linq.XName.op_Implicit(String expandedName)
       at datagrid.MainWindow.<.ctor>b__0(XElement item) in \datagrid\MainWindow.xaml.cs:line 24
       at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
       at datagrid.MainWindow..ctor() in datagrid\MainWindow.xaml.cs:line 28
  InnerException: 


A: Looking at your code, I guess your are trying to retrieve this part of the XML file (the value items):
<wind-speed type="sustained" units="knots" time-layout="k-p3h-n34-3">
    <name>Wind Speed</name>
    <value>20</value>
    <value>13</value>
    ...
    <value>3</value>
</wind-speed>

Try with this query instead:
var i = from item in xmlDoc.Descendants("wind-speed") \\ get wind-speed descendants
        where item.Elements("name").First().Value == "Wind Speed" \\ since there are two types of wind-speed nodes,
                                                                  \\ we want that whose first item is called "Wind Speed"
        from value in item.Elements("value")  \\ get values inside wind-speed node
        select new
        {
            WindSpeed = value.Value \\ return values inside wind-speed node
        };

I think that when you refer to attributes with white spaces you are speaking about <name>Wind Direction</name>, but this is not an attribute. Take this line:
<wind-speed type="sustained" units="knots" time-layout="k-p3h-n34-3">

type,units and time-layout are attributes, and as you can see none of them has white spaces inside their name, because it's not allowed.
