Loading Data, load only the name in the XML file I did the save.

This is the


file : // The trainingfaces file

<?xml version="1.0" encoding="utf-8"?>
         <informations>Student in MS university</informations>
         <FILE>face_john 25Student in MS university_905807542.jpg</FILE>
         <informations>engineer ....</informations>
         <FILE>face_mark 40engineer ....._390671740.jpg</FILE>

The problem that I can load only the name .how I can load age and extra information with the name . I load the name and put it in List <string> and make it equal to face label. I want it load Age , and the other information's .

private bool LoadTrainingData(string Folder_location)
    if (File.Exists(Folder_location +"\\TrainedLabels.xml"))
            //message_bar.Text = "";
            FileStream filestream = File.OpenRead(Folder_location + "\\TrainedLabels.xml");
            long filelength = filestream.Length;
            byte[] xmlBytes = new byte[filelength];
            filestream.Read(xmlBytes, 0, (int)filelength);

            MemoryStream xmlStream = new MemoryStream(xmlBytes);

            using (XmlReader xmlreader = XmlTextReader.Create(xmlStream))
                while (xmlreader.Read())
                    if (xmlreader.IsStartElement())
                        switch (xmlreader.Name)
                            case "NAME":
                                if (xmlreader.Read())
                                    Names_List_ID.Add(Names_List.Count); //0, 1, 2, 3....
                                    NumLabels += 3;

                            case "FILE":
                                if (xmlreader.Read())
                                    //PROBLEM HERE IF TRAININGG MOVED
                                    trainingImages.Add(new Image<Gray, byte>(Application.StartupPath + "\\TrainedFaces\\" + xmlreader.Value.Trim()));
                           // case "Age":
                               //   if (xmlreader.Read())
                                  //    Age_List.Add(xmlreader.Value.Trim());

                               //   }
                                // break;
            ContTrain = NumLabels;

Ahh XML, it can be a stumper at first, but once you learn the tricks, it becomes easy and powerful. Let's see, where did I leave that code (I'll convert it over to match yours)

List<string> Names = new List<string>();
List<int> Ages = new List<int>();
List<string> Informations = new List<string>();
List<string> ImageFile = new List<string>();

//Load in the document, and convert it over to an XML (document needs to be a valid
//XML document for this to work)
XmlDocument myDocument = new XmlDocument();
myDocument.LoadXml(Folder_location +"\\TrainedLabels.xml");

//Select all the Nodes that are "<FACE>" and then index through each
//retriveing the values from the nodes inside.
foreach(XmlNode node in myDocument.SelectNodes("//FACE"))

That should do it for you (if this is what you were asking), or at least get your started in the right direction (I believe I wrote this correctly, I unfortantly left the document I wrote up at work that would have been nice to compare against, but I still remember it).

You should note that retrieveing XML values like this
<field>"SOME VALUE"</field>
is done differently then if you wanted to fetch a value like
<field specialValue="SOME VALUE"/>
If you are interested in how to retrieve values like this let me, I have code laying around for that to

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.