Below is the XML data I am getting from a URL. When I view source, here is how it looks:
<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>
I am able to read the content in a message box:
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());
}
}
I would like to save this to an array, or a list, or LINQ.
How can i use the code above with the XML above and make it into an array.
I only want all the data within <someschemas>. and just these values as key/value pairs:
<title type='html'>test</title>
<summary type='html'>test</summary>
<descriptions type='html'>test</descriptions>
<actor>
<name>teest</name>
<phone>test</phone>
</actor>
Employeeclass? You are looping through stuff already, just add it to a class, give that some semantic meaning and you are sorted. For instance, instead of showingemployee.Value, add it to aList.WebResponseandStreamareIDisposableresources and therefore should be withinusingblocks.