In the following fragment, load_training_data does what you want using XPath[^].
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Xml;
namespace LoadingFace
{
public partial class LoadingFace : Form
{
const string PATH = @"TrainedLabels.xml";
List < string > ages = new List<string> ( );
List < string > files = new List<string> ( );
List < string > informations = new List<string> ( );
List < string > names = new List<string> ( );
public LoadingFace ( )
{
InitializeComponent ( );
load_training_data ( PATH );
}
string retrieved_training_data ( XmlNode root,
string item )
{
string inner_text;
XmlNode node = null;
try
{
node = root.SelectSingleNode ( item );
inner_text = node.InnerText.Trim ( );
}
catch
{
inner_text = String.Empty;
}
return ( inner_text );
}
void load_training_data ( string path )
{
try
{
XmlNodeList node_list;
XmlNode root;
XmlDocument xml_document = new XmlDocument ( );
ages.Clear ( );
files.Clear ( );
informations.Clear ( );
names.Clear ( );
xml_document.Load ( path );
root = xml_document.DocumentElement;
node_list = root.SelectNodes ( "face" );
foreach ( XmlNode node in node_list )
{
string age = String.Empty;
string file = String.Empty;
string information = String.Empty;
string name = String.Empty;
age = retrieved_training_data ( node, "age" );
ages.Add ( age );
file = retrieved_training_data ( node, "file" );
files.Add ( file );
information = retrieved_training_data (
node,
"informations" );
informations.Add ( information );
name = retrieved_training_data ( node, "name" );
names.Add ( name );
}
}
catch ( Exception ex )
{
}
}
}
}
</string></string></string></string>
It uses the helper function retrieved_training_data.
Hope that helps.