如何解析此xml内容。
<Content>
<caption> Today Headline </caption>
<s1>
<name>6</name>
<name>4</name>
<name>4</name>
</s1>
<s2>
<name>3</name>
<name>6</name>
<name>0</name>
</s2>
</Content>
mycode的:
date = (from story
in xmlParser.Descendants("s1")
select new EspnViewModel
{
Category = story.Element("name").Value,
}).ToList();
return data;
我很难弄清楚如何解析所有问题。
答案 0 :(得分:0)
为什么不使用xmlParser.Descendants(“name”)?
编辑:
var caption = xmlParser.Descendants(“caption”)。First()。InnerText;
var names = from xmlParser.Descendants(“name”)中的故事 选择新的EspnViewModel { Category = story.InnerText })ToList();
注意:我正在急忙写这个,但你明白了......
答案 1 :(得分:0)
private List<yourclass> ReadList()
{
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (myIsolatedStorage.FileExists("xmlName.xml"))
{
using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("xmlName.xml", FileMode.Open))
{
XmlSerializer serializer = new XmlSerializer(typeof(List<your class>));
List<yourclass> data = (List<yourclass>)serializer.Deserialize(stream);
return data.ToList();
}
}
else
{
return null;
}
}
}