开发者

XDocument doesn't appear to exist in System.Xml namespace

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;开发者_Go百科
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?")

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜