English 中文(简体)
阅读 Xml文档和将内容保存在记忆中
原标题:Read Xml file and save content into memory WP7

我有一张带有数据的xml,在这种情况下,存储在互联网上。 想读到窗户电话中的xml,将其保存到记忆中。 如何做到这一点? 任何辅导?

最佳回答

让我们把任务分成两部分

1. 下载XML文档,其中载有图像途径

2. 阅读XML文档和对这一动态途径具有约束力的图像控制

3. 首先让收益:

1. 下载XML文档,其中载有图像途径

http://server_adrs/XML_FILE

iso_path Path within Isolated Deposit where uoshi to Save XML file.

    public void GetXMLFile(string path)
    {
        WebClient wcXML = new WebClient();
        wcXML.OpenReadAsync(new Uri(path));
        wcXML.OpenReadCompleted += new OpenReadCompletedEventHandler(wc);

    }

    void wc(object sender, OpenReadCompletedEventArgs e)
    {
        var isolatedfile = IsolatedStorageFile.GetUserStoreForApplication();
        using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(iso_path, System.IO.FileMode.Create, isolatedfile))
        {
            byte[] buffer = new byte[e.Result.Length];
            while (e.Result.Read(buffer, 0, buffer.Length) > 0)
            {
                stream.Write(buffer, 0, buffer.Length);
            }
            stream.Flush();
            System.Threading.Thread.Sleep(0);
        }            
    }

2. 阅读XML文档,对动态路径进行具有约束力的图像控制

这里我有一个显示图像的清单,因此,将按下文对图像进行约束。

    public IList<Dictionary> GetListPerCategory_Icon(string category, string xmlFileName)
    {
        using (var storage = IsolatedStorageFile.GetUserStoreForApplication())
        {
            if (storage.FileExists(xmlFileName))
            {
                using (Stream stream = storage.OpenFile(xmlFileName, FileMode.Open, FileAccess.Read))
                {
                    try
                    {
                        loadedData = XDocument.Load(stream);
                        var data = from query in loadedData.Descendants("category")
                                   where query.Element("name").Value == category
                                   select new Glossy_Test.Dictionary
                                   {
                                        Image=GetImage((string)query.Element("iconpress")),//This is a function which will return Bitmap image

                                   };
                        categoryList = data.ToList();
                    }

                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message.ToString(), (((PhoneApplicationFrame)Application.Current.RootVisual).Content).ToString(), MessageBoxButton.OK);
                        return categoryList = null;
                    }
                }
            }
        }

        return categoryList;
    }

三、上述职能的定义

     public BitmapImage GetImage(string imagePath)
    {
        var image = new BitmapImage();
        imagePath = "/Glossy" + imagePath;
        using (var storage = IsolatedStorageFile.GetUserStoreForApplication())
        {
            if (storage.FileExists(imagePath))
            {
                using (Stream stream = storage.OpenFile(imagePath, FileMode.Open, FileAccess.Read))
                {                       
                    image.SetSource(stream);                        

                }
            }
        }
        return image;
    }
问题回答

您可使用WebClient从服务器中提取xml,然后在你的回响中将其作为XDocument予以节省。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签