I'm trying to create a Silverlight application (for the first time) that includes parsing XML from a site and displaying information. For this, I use Visual Studio 2008 on Windows XP Service Pack 3. I also have the .NET Framework 3.5 SP1 installed.
My problem is that no XML parser that I saw on the Internet works. At the top of my code, I have two lines that I consider necessary (using "System.xml;" and using "System.linq;"), but XDocument, XMLReader, XMLDocument and any others that I found do not work, returning an error that the type or namespace could not be found. I have a .NET Framework.
In this problem, I did absolutely nothing on the Internet. Does anyone have any idea?
EDIT: I just discovered that when I open a file outside the context of a Silverlight project, it can use XDocument. Only when I open the whole project does my problem arise
Here is a sample code showing the problem:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml.Linq;
namespace LastfmAmazon
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
}
public void DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
XDocument doc = XDocument.Parse(e.Result);
}
public void Button_Click(object sender, RoutedEventArgs e)
{
if (uname.Text != String.Empty)
{
App app = (App)Application.Current;
app.UserName = uname.Text;
String getTopArtists = "http://ws.audioscrobbler.com/2.0/?method=user.gettopartists&user=" + app.UserName + "&api_key=d2d620af554a60f228faed8d502c4936";
uname.Text = "Try Another One!";
WebClient web = new WebClient();
WebClient client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DownloadStringCompleted);
client.DownloadStringAsync(new Uri(getTopArtists));
}
}
}
}
Error 1: this line contains the following error: The type or name of the namespace "Linq" does not exist in the namespace "System.Xml" (do you miss the assembly reference?)
Error 2: this line contains the following error: The type or name of the namespace "XDocument" does not exist in the namespace "System.Xml" (do you miss the assembly reference?)
EDIT 2: As soon as I figured out what it meant to “add a link” to the library, Anthony's answer solved the problem.