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

只愿长相守 提交于 2020-01-03 08:14:12

问题


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


回答1:


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?")



来源:https://stackoverflow.com/questions/4787387/xdocument-doesnt-appear-to-exist-in-system-xml-namespace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!