Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从wp8中的隔离文件获取xml文件_C#_.net_Xml_Windows Phone 8 - Fatal编程技术网

C# 如何从wp8中的隔离文件获取xml文件

C# 如何从wp8中的隔离文件获取xml文件,c#,.net,xml,windows-phone-8,C#,.net,Xml,Windows Phone 8,我尝试获取Xml文件并绑定到列表 这是我的Xml文件 - <data> - <Bookmarkdata> <Bookname>TheNfame</Bookname> <Bookid>5a1df538-6e91-4a39-819d-e043c9881fb7</Bookid> <Pageno>0</Pageno> </Bookmarkdata&g

我尝试获取Xml文件并绑定到列表 这是我的Xml文件

- <data>
  - <Bookmarkdata>
      <Bookname>TheNfame</Bookname> 
      <Bookid>5a1df538-6e91-4a39-819d-e043c9881fb7</Bookid> 
      <Pageno>0</Pageno> 
    </Bookmarkdata>
  - <Bookmarkdata>
      <Bookname>TheNfame</Bookname> 
      <Bookid>5a1df538-6e91-4a39-819d-e043c9881fb7</Bookid> 
      <Pageno>1</Pageno> 
    </Bookmarkdata>
 </data>
但作为回报,这是一个错误 值不能为null

参数名称:元素

在我的代码中doc=XDocument.Load(sr)
我有一个xml数据备份时间,但在下一行是错误的,请帮助

您的LINQ到xml查询有点不正确<代码>查询变量在此处表示
元素:

var data = from query in doc.Descendants("data")
                               select new Bookmarkdata
                               {
                                   Bookname = (string)query.Element("Bookname"),
                                   Bookid = (string)query.Element("Bookid"),
                                   BookPath = (string)query.Element("BookPath"),
                                   Pageno = (int)query.Element("Pageno")
                               };
所以它没有名为Bookname、Bookid、BookPath或Pageno的直接子级。我想您应该从
元素中进行选择:

var data = from query in doc.Descendants("Bookmarkdata")
                       select new
                       {
                           Bookname = (string)query.Element("Bookname"),
                           Bookid = (string)query.Element("Bookid"),
                           BookPath = (string)query.Element("BookPath"),
                           Pageno = (int)query.Element("Pageno")
                       };

谢谢,我还有一个问题是,如何使用where查询检查名称已经存在或不象这个字符串data=来自doc.substands(“Bookmarkdata”)中的查询where((string)query.Element(“Bookname”)==“God”)&((string)query.Element(“Pageno”)==5)选择(字符串)query.Element(“Bookname”).ToString();
var data = from query in doc.Descendants("Bookmarkdata")
                       select new
                       {
                           Bookname = (string)query.Element("Bookname"),
                           Bookid = (string)query.Element("Bookid"),
                           BookPath = (string)query.Element("BookPath"),
                           Pageno = (int)query.Element("Pageno")
                       };