I'm having what I think will probably be a really simple problem, in developing my first WP7 app I've come to the stage of accessing my Site's api and parsing the XML, however I'm stumbling just at trying to use XDocument.
I search around and found this example code: Load an XML file from a website into XDocument (Silverlight and Windows Phone 7) but the XDocument type does not exist, I understand it is supposed to exist in the System.Xml namespace which I am using, but the error still remains, what have I missed?
Developing on Visual Studio 2010 Express for Windows Phone, code for this class is below:
using System;
using System.Net;
using System.IO;
using System.Xml;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace Application
{
public class DataRetriever
{
public void parseNewsXML()
{
WebClient client = new WebClient();
client.OpenReadCompleted += (sender, e) =>
{
if (e.Error != null)
return;
Stream str = e.Result;
XDocument xdoc = XDocument.Load(str);
};
}
}
Exact error being thrown is: Error 1 The type or namespace name 'XDocument' could not be found (are you missing a using directive or an assembly reference?)
Thanks in advance
For Silverlight, that class is in System.Xml.Linq.dll
, according to MSDN - so add a reference to System.Xml.Linq.dll
. You will also need a using
directive at the top of your code file:
using System.Xml.Linq;
(these are exactly the same two suggestions that the compiler itself makes: "are you missing a using directive or an assembly reference?")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With