Parsing inner tag with its value

后端 未结 1 1013
予麋鹿
予麋鹿 2020-12-22 00:03

I have a plist in this format:



    
        Title&         


        
相关标签:
1条回答
  • 2020-12-22 00:26

    Yes, there is an easier way:

    XDocument doc = XDocument.Load("input.xml");// plist file name
    
    var chapters = (from d in doc.Root.Element("array").Elements("dict")
                    select new Chapter
                    {
                        Title = (string)d.Element("string"),
                        SubTitles = d.Element("array")
                                     .Elements("dict")
                                     .Elements("string")
                                     .Select(s => (string)s)
                                     .ToList()
                    }).ToList();
    

    You didn't show your classes, so I assumed it looks like that:

    class Chapter
    {
        public string Title { get; set; }
        public List<string> SubTitles { get; set; }
    }
    
    0 讨论(0)
提交回复
热议问题