该文件是
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>subscriptions</title>
</head>
<body>
<outline text="Tech" title="Tech">
<outline type="rss" text="The Verge" title="The Verge" xmlUrl="http://www.theverge.com/rss/full.xml" htmlUrl="https://www.theverge.com/"/>
</outline>
</body>
</opml>
并通过使用代码从读取的内容中提取属性
public List<FeedsMainMenuItem> Import(string uri)
{
XDocument doc = XDocument.Parse(uri);
//XDocument doc = XDocument.Load(uri);
List<FeedsMainMenuItem> t = doc
.Descendants("outline")
.Elements("outline")
.Select(o => new FeedsMainMenuItem
{
FeedUrl = o.Attribute("xmlUrl").Value,
Title = o.Attribute("title").Value,
SiteUrl = o.Attribute("htmlUrl")?.Value,
Favicon = "https://www.google.com/s2/favicons?domain_url=" + o.Attribute("htmlUrl")?.Value
})
.ToList();
return t;
}
但无法读取“htmlUrl”属性值
SiteUrl = o.Attribute("htmlUrl")?.Value
那么,为什么连价值都在那里,解决方案是什么
编辑:FeedsMainMenuItem 类
公共类 FeedsMainMenuItem {
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string FeedUrl { get; set; }
public string Title { get; set; }
public string Favicon { get; set; }
public string SiteUrl { get; set; }
public DateTime LastUpdated { get; set; }
[Ignore]
public Type ViewModelToLoad
{
get { return JsonConvert.DeserializeObject<Type>(ViewModelToLoadString) ?? typeof(RssFeedViewModel); }
set { ViewModelToLoadString = JsonConvert.SerializeObject(value); }
}
public string ViewModelToLoadString { get; set; }
//public Type ViewModelToLoad { get; set; } = typeof(RssFeedViewModel);
[OneToMany]
public List<RssSchemaExtended> FeedsItems { get; set; }
}