下面是我从 URL 获取的 XML 数据。当我查看源代码时,它的外观如下:
<xml>
<beginning>
<id>information from rss provider here</id>
<updated>information from rss provider here</updated>
<link rel='alternate' type='text/html' href='tttt' title='alternate'/>
<link rel='self' type='application/atom+xml' href='tttt'/>
<someschemas>
<id>test</id>
<movieid>test</movieid>
<updated>teeeeest</updated>
<types scheme='vals' term='test'/>
<title type='html'>test</title>
<summary type='html'>test</summary>
<descriptions type='html'>test</descriptions>
<link rel='alternate' type='text/html' href='tttt' title='alternate'/>
<link rel='self' type='application/atom+xml' href='tttt'/>
<actor>
<name>teest</name>
<phone>test</phone>
</actor>
</someschemas>
<someschemas>
<id>test</id>
<movieid>test</movieid>
<updated>teeeeest</updated>
<types scheme='vals' term='test'/>
<title type='html'>test</title>
<summary type='html'>test</summary>
<descriptions type='html'>test</descriptions>
<link rel='alternate' type='text/html' href='tttt' title='alternate'/>
<link rel='self' type='application/atom+xml' href='tttt'/>
<actor>
<name>teest</name>
<phone>test</phone>
</actor>
</someschemas>
<someschemas>
<id>test</id>
<movieid>test</movieid>
<updated>teeeeest</updated>
<types scheme='vals' term='test'/>
<title type='html'>test</title>
<summary type='html'>test</summary>
<descriptions type='html'>test</descriptions>
<link rel='alternate' type='text/html' href='tttt' title='alternate'/>
<link rel='self' type='application/atom+xml' href='tttt'/>
<actor>
<name>teest</name>
<phone>test</phone>
</actor>
</someschemas>
</beginning>
</xml>
我能够阅读消息框中的内容:
WebRequest request = WebRequest.Create("http://www.test.com/file.xml");
WebResponse response = request.GetResponse();
Stream dataStream = response.GetResponseStream();
XElement xelement = XElement.Load(dataStream);
IEnumerable<XElement> employees = xelement.Elements();
foreach (var employee in employees)
{
if (employee.Elements("content") != null)
{
MessageBox.Show(employee.Value.ToString());
}
}
我想将它保存到数组、列表或 LINQ 中。
我怎样才能将上面的代码与上面的 XML 一起使用并将其变成一个数组。
我只想要其中的所有数据<someschemas>.
以及这些值作为键/值对:
<title type='html'>test</title>
<summary type='html'>test</summary>
<descriptions type='html'>test</descriptions>
<actor>
<name>teest</name>
<phone>test</phone>
</actor>