Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.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# 在windows phone 7中解析xml时出错_C#_Linq_Windows Phone 7_Xml Parsing - Fatal编程技术网

C# 在windows phone 7中解析xml时出错

C# 在windows phone 7中解析xml时出错,c#,linq,windows-phone-7,xml-parsing,C#,Linq,Windows Phone 7,Xml Parsing,下面是要在我的windows phone应用程序中解析的xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist> <dict> <key>2013</key> &

下面是要在我的windows phone应用程序中解析的xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist>
   <dict>
  <key>2013</key>
   <dict>
      <key>January</key>
        <dict>
        <key>Girivalam</key>
        <dict>
            <key>StartDate</key>
            <date>2013-01-26T04:10:00Z</date>
            <key>EndDate</key>
            <date>2013-01-27T05:26:00Z</date>
            <key>FullMoon</key>
            <date>2013-01-26T04:10:00Z</date>
        </dict>
                </dict>
       </dict>
      </dict>
</plist>

2013
一月
吉里瓦姆
起始日期
2013-01-26T04:10:00Z
结束日期
2013-01-27T05:26:00Z
满月岛
2013-01-26T04:10:00Z
我用下面的代码解析了它

   private void Parsing()
    {
        using (XmlReader reader = XmlReader.Create(new StringReader("/Parse/appmodel-data.xml")))
        {
            XDocument document = XDocument.Load(reader);
            IEnumerable<XElement> AuthElement = from elements in document.Descendants("dict")
                                                select elements;
        }
    }
private void解析()
{
使用(XmlReader=XmlReader.Create(newstringreader(“/Parse/appmodel data.xml”))
{
XDocument document=XDocument.Load(读卡器);
IEnumerable AuthElement=来自document.subjects(“dict”)中的元素
选择元素;
}
}
当我执行应用程序时,我收到错误“根级别的数据无效。第1行,位置1。”有人能纠正我哪里出错了吗

提前谢谢

StreamResourceInfo xml = Application.GetResourceStream(new Uri("/ProjectName;component/FileFolder/filename.xml", UriKind.Relative));
XElement xmlElement = XElement.Load(xml.Stream);

你可以使用你的陈述本身。唯一的问题是正确引用XML的路径。

将文件标记为资源,然后尝试以下操作

System.IO.Stream fileStream = Application.GetResourceStream(new Uri(@"/Change this with the AssemblyName;component/Parse/appmodel-data.xml",UriKind.Relative)).Stream;

XDocument document = XDocument.Load(fileStream);                        
IEnumerable<XElement> AuthElement = from elements in document.Descendants("dict")
                                        select elements;
System.IO.Stream fileStream=Application.GetResourceStream(新Uri(@)/将其更改为AssemblyName;component/Parse/appmodel data.xml”,UriKind.Relative)).Stream;
XDocument document=XDocument.Load(fileStream);
IEnumerable AuthElement=来自document.subjects(“dict”)中的元素
选择元素;

设置一个断点,查看文档是否加载到文档变量中a我完成了…在这一行中,只有我得到了此运行时异常…XML文件是应用程序资源吗?是的…它是一个应用程序资源其他人已经解释了如何执行此操作,但您也应该了解出了什么问题:看看
StringReader
做了什么。当前您根本没有加载文件。。。您正在尝试解析字符串“/parse/appmodel data.xml”,就像解析xml.ya一样。我将文件标记为资源。。但仍在获取null referenceprivate void Parsing(){System.IO.Stream fileStream=Application.GetResourceStream(新Uri(@)/Data%20Parsing;component/Parse/appmodel Data.xml”,UriKind.Relative)).Stream;XDocument document document=XDocument.Load(fileStream);IEnumerable AuthElement=来自文档中的元素。子体(“dict”)选择元素;}是程序集名称“数据解析”?我得到了解决方案。。这对我很有效。。var resource=Application.GetResourceStream(新Uri(@“/Data%20Parsing;component/Parse/appmodel Data.xml”,UriKind.Relative));StreamReader StreamReader=新的StreamReader(resource.Stream);字符串x=streamReader.ReadToEnd();