Link to home
Start Free TrialLog in
Avatar of Aikencura
Aikencura

asked on

Linq to xml not working

Hi

Can somebody explain me why my code isn't working?



 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Data;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Linq;
using System.Diagnostics;

namespace TelSearchModule
{
    public partial class _Default : System.Web.UI.Page
    {

       


        protected void Page_Load(object sender, EventArgs e)
        {
            ///Start Test
            
            // Load XML doc
            XDocument rssFeed = XDocument.Load("http://tel.search.ch/examples/api-response.xml");
            // Define XML Namespace
            XNamespace Atom = "http://www.w3.org/2005/Atom";
            XNamespace OpenSearch = "http://a9.com/-/spec/opensearchrss/1.0/";
            XNamespace tel = "http://tel.search.ch/api/spec/result/1.0/";

            var entries = from entry in rssFeed.Descendants("entry")
                          select new
                          {
                              Title = entry.Element("title").Value,
                              FirstName = entry.Element("tel:FirstName").Value
                          };
}
}
}

Open in new window

Avatar of Bob Learned
Bob Learned
Flag of United States of America image

If the elements are in a different namespace, then you need to include those in the XDocument query.

Example:

http://msdn.microsoft.com/en-us/library/cc165615.aspx


planetsDoc = XDocument.Load("../../Planets.xml");
stacky.DataContext = planetsDoc.Element("{http://planetsNS}SolarSystemPlanets").Elements();
Avatar of Aikencura
Aikencura

ASKER

I don't understand, can you explain in "noob" language please..with my code.
If you test your suggestion, you get:
{"The '{' character, hexadecimal value 0x7B, cannot be included in a name."}
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial