反序列化对象后如何创建 XDocument 实例来加载 XML 文件?

发布于 2024-10-06 14:07:55 字数 1144 浏览 1 评论 0原文

我正在开发 Windows Phone 7 应用程序。我是 Windows Phone 7 应用程序的新手。我指的是以下关于 XML Serialization & 的链接:反序列化。

http://www.codeproject.com/KB/windows-phone-7 /wp7rssreader.aspx

在上面的链接中,LoadFromIso() 函数用于 XML 反序列化。我想在上面的链接中反序列化后加载xml文件。在简单的一种情况下,我们可以按照以下代码执行此操作。与以下代码类似,我想要上面链接中的“doc”。在下面的代码中,我们可以通过使用 LINQ to XML 和以下语句对 XML 文件执行各种操作

doc = XDocument.Load(isfStream);  

完整的代码如下

IsolatedStorageFile isfData = IsolatedStorageFile.GetUserStoreForApplication();
            XDocument doc = null;
            IsolatedStorageFileStream isfStream = null;
            if (isfData.FileExists(strXMLFile))
            {
                isfStream = new IsolatedStorageFileStream(strXMLFile, FileMode.Open, isfData);
                doc = XDocument.Load(isfStream);                
                isfStream.Close();
            }

以类似的方式我想要反序列化对象后的 XDocument 实例,以便我可以执行各种操作使用 LINQ to XML 对 XML 文件进行操作。您能否向我提供任何代码或链接,通过它们我可以获取 XDocument 的实例,以便我可以加载 XML 文件和链接?使用 LINQ to XML 对 XML 文件执行各种操作?

I am developing window phone 7 application. I am new to the window phone 7 application. I am referring to the following link for XML Serialization & Deserialization.

http://www.codeproject.com/KB/windows-phone-7/wp7rssreader.aspx

In the above link the LoadFromIso() function is used for XML Deserialization. I want to load the xml file after deserialization in the above link. In simple one case we can do this as in the following code. Similar to the following code I want "doc" in the above link. In the following code we can perform the various opeations on the XML file by using LINQ to XML with following statement

doc = XDocument.Load(isfStream);  

The complete code is as follows

IsolatedStorageFile isfData = IsolatedStorageFile.GetUserStoreForApplication();
            XDocument doc = null;
            IsolatedStorageFileStream isfStream = null;
            if (isfData.FileExists(strXMLFile))
            {
                isfStream = new IsolatedStorageFileStream(strXMLFile, FileMode.Open, isfData);
                doc = XDocument.Load(isfStream);                
                isfStream.Close();
            }

In the similar way I want the instance of the XDocument after deserializing the object so that I can perform the various operations on the XML file by using LINQ to XML. Can you please provide me any code or link through which I can obtain the instance of the XDocument so that I can load the XML file & perform the various operation on the XML file by using the LINQ to XML ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

各自安好 2024-10-13 14:07:55

代码中的变量 doc 是反序列化内容的 XDocument。
您可以对 doc 执行操作。

The variable doc in your code is an XDocument of the deserialized content.
You can perform your operations on/with doc.

谈场末日恋爱 2024-10-13 14:07:55

一个简单的 WP7 项目演示了使用 XDocument 和 LINQ 加载 XML 以及将数据绑定到列表框。正如 Matt 建议的那样,工作在您的 XDocument 实例上完成。

将 Linq 数据源绑定到列表框

A simple WP7 project demonstrating loading XML using XDocument and LINQ and data binding to a listbox here. As Matt advises the work gets done on your XDocument instance.

binding a Linq datasource to a listbox

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文