silverlight   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何在SilverLight项目中使用XDocument类(C#)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我正在尝试创建一个Silverlight应用程序(第一次),它涉及从站点解析XML并显示信息.为此,我在Windows XP service Pack 3上使用Visual studio 2008.我还安装了.NET Framework 3.5 SP1. 我的问题是我在互联网上看到的XML解析器都没有.我的代码的顶部我有两行我认为是必要的(使用“System.xml;”并使用“System.lin
@H_197_18@ 我正在尝试创建一个Silverlight应用程序(第一次),它涉及从站点解析XML并显示信息.为此,我在Windows XP service Pack 3上使用Visual studio 2008.我还安装了.NET Framework 3.5 SP1.

我的问题是我在互联网上看到的XML解析器都没有.我的代码的顶部我有两行我认为是必要的(使用“System.xml;”并使用“System.linq;”)但XDocument,XMLReader,XMLDocument和我发现的任何其他行都不起作用,返回错误无法找到类型或命名空间.我有.NET Framework.

关于这个问题我在互联网上完全没有任何改变.有没有人有任何想法?

编辑:我刚刚发现,当我在Silverlight项目的上下文之外打开文件时,它可以使用XDocument.只有当我打开整个项目时才会出现问题

以下是一些显示问题的示例代码

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; //Error 1 (See below)

namespace LastfmAmazon
{
    public partial class Page : UserControl
    {
        public Page()
        {
            InitializeComponent();
        }

        public void DownloadStringCompleted(object sender,DownloadStringCompletedEventArgs E)
        {
            XDocument doc = XDocument.Parse(e.Result); //Error 2: see below

        } 

        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));
            }
        }
    }   
}

错误1:此行包含以下错误名称空间“System.Xml”中不存在类型或命名空间名称“Linq”(您是否缺少程序集引用?)

错误2:此行包含以下错误名称空间“System.Xml”中不存在类型或命名空间名称“XDocument”(您是否缺少程序集引用?)

编辑2:一旦我用Google搜索“为图书馆添加”意味着什么,安东尼的答案就解决了这个问题.

解决方法

认情况下,Silverlight项目将包含System.Xml dll,但XDcoument包含在System.Xml.Linq dll中,您必须将添加项目中.

大佬总结

以上是大佬教程为你收集整理的如何在SilverLight项目中使用XDocument类(C#)全部内容,希望文章能够帮你解决如何在SilverLight项目中使用XDocument类(C#)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。