I have this xml file which contains information from tagchimp, but the file contains way to much information. How do i only load the information i need. I have found some code:
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlElement root = doc.DocumentElement;
XmlNodeList nodes = root.SelectNodes("movie");
foreach (XmlNode node in nodes)
{
string date = node["tagChimpID"].InnerText;
string name = node["locked"].InnerText;
Console.WriteLine("Id:" + date + " Locked:" + name);
}
but it only loads the elements not the child elements, some for example movieTitle or shortDescription
I found a way:
public static string Test(string path, XmlElement nodes)
{
string Name = "";
string releaseDate = "";
XmlNodeList xnList = nodes.SelectNodes("/items/movie");
XmlNode eNode;
foreach (XmlNode xn in xnList)
{
eNode = xn.SelectSingleNode("movieTags/info/movieTitle");
if (eNode != null)
{
Name = eNode.InnerText;
}
eNode= xn.SelectSingleNode("movieTags/info/releaseDate");
releaseDate = eNode.InnerText;
}
but it's not the most practical way to come by it.
Since you are using .NET, you might spend some time learning LINQ to XML, since it sounds like it would do what you want.
There is a lot of online documentation, in particular how to do various basic queries to get information from specific nodes: http://msdn.microsoft.com/en-us/library/bb943906.aspx
You could also get the same results with XPath.
Or you could manually traverse the nodes, although you would have to handle the child nodes properly (as you already discovered).