C# 如何在c中通过XDocument列出xml元素?

C# 如何在c中通过XDocument列出xml元素?,c#,xml,pocketpc,C#,Xml,Pocketpc,我在这里读了很多关于xml的主题,并尝试了一些,但仍然无法解决这个问题。 我必须列出xml文件中的项目并将其加载到ListView。我的项目是在Pocket-PC中完成的。以下是示例xml内容 <? xml version="1.0" encoding="utf-8" ?> <Library> <Item> <Name>Picture</Name> <FullPath>\My Devi

我在这里读了很多关于xml的主题,并尝试了一些,但仍然无法解决这个问题。 我必须列出xml文件中的项目并将其加载到ListView。我的项目是在Pocket-PC中完成的。以下是示例xml内容

<? xml version="1.0" encoding="utf-8" ?>
<Library>
    <Item>
        <Name>Picture</Name>
        <FullPath>\My Device\My Documents\Picture</FullPath>
        <SystemFullpath>\Program Files\Explorer\Library</SystemFullpath>
        <Created>0001-01-01T00:00:00</Created>
    </Item>
    <Item>
        <Name>Video</Name>
        <FullPath>\My Device\My Documents\Video</FullPath>
        <SystemFullpath>\Program Files\Explorer\Library</SystemFullpath>
        <Created>0001-01-01T00:00:00</Created>
    </Item>
    <Item>
        <Name>File</Name>
        <FullPath>\My Device\My Documents\File</FullPath>
        <SystemFullpath>\Program Files\Explorer\Library</SystemFullpath>
        <Created>0001-01-01T00:00:00</Created>
    </Item>
</Library>  
图书馆实体:

public class Library
{
    public Library() { }

    // Unique
    public string Name { get; set; }

    public string Fullpath { get; set; }

    public string SystemFullpath { get; set; }

    public DateTime Created { get; set; }

    public List<Items> Items { get; set; }
}  
以及用于检索返回错误的项的代码:

public List<Library> RetrieveAllLibrary()
{
    List<Library> libList = new List<Library>();
    if (File.Exists(fileName))
    {
        XDocument xDoc = XDocument.Load(fileName);

        var items = from item in xDoc.Descendants("Item")
                    select new
                    {
                        Name = item.Element("Name").Value,
                        FullPath = item.Element("FullPath").Value,
                        Created = item.Element("Created").Value
                    };

        if (items != null)
        {
            foreach (var item in items)
            {
                Library lib = new Library();
                lib.Name = item.Name;
                lib.Fullpath = item.FullPath;
                lib.Created = DateTime.Parse(item.Created);
                libList.Add(lib);
            }
        }
    }
    return libList;
}  
错误显示:


我希望我能解释清楚。谢谢你的帮助

您的问题是这一行:

new XElement("Fullpath", lib.Fullpath),
该名称用小写字母p键入,随后使用大写字母p的FullPath


如果要保留数据,还应将XML文件中的所有Fullpath替换为Fullpath。

是这样吗?哇!你明白了。我甚至没有注意到。谢谢
new XElement("Fullpath", lib.Fullpath),