/// <summary>
        /// Searches the list of XMLRecords based on the passed ID
        /// </summary>
        /// <param name="ID">a CSV string with all the IDs of the XML record to be found</param>
        /// <returns>the index of the XMLTree if found else -1</returns>
        public int IndexOf(string ID)
        {
            if (XMLRecordList == null)
            {
                return(-1);
            }
            XMLRecord searchID = new XMLRecord(ID);

            return(XMLRecordList.IndexOf(searchID));
        }
        ///<summary>
        /// This function processes the given XML file according to the processing type provided.
        ///</summary>
        ///<param name="Type">Indicates how the XML file should be processed.see <see cref="XMLRecordFileProcessor.ProcessType"/></param>
        public void Process(ProcessType Type)
        {
            int           i            = 0;
            string        ExceptionMsg = ""; //used by the exception thrown if something goes wrong
            AnonymizerXML anonymizer   = null;
            string        output_anonymized_filename = "";

            if (Type == ProcessType.AnonymizeToFiles || Type == ProcessType.Anonymize)
            {
                anonymizer = new AnonymizerXML(_filename);
            }

            if (Type == ProcessType.Anonymize)
            {
                using (StreamWriter anonymized = File.CreateText(tempfile))
                    anonymized.WriteLine(xmlDecl);
            }

            if (Type == ProcessType.ToMemory)
            {
                _XMLRecords = new List <XMLRecord>();
            }

            //Iterate through the XMLfile
            try {
                //create the namespace manager
                XmlNamespaceManager nsmgr = null;

                //Process XMLRecords
                XMLRecordFileIterator myXMLRecFile = XMLRecordFileIterator.GetXMLRecordFileIterator(this.getFullFilename()
                                                                                                    , _containerTags
                                                                                                    , _IDTags);
                //Add namespace tag (root element) to anonymized file
                if (Type == ProcessType.Anonymize)
                {
                    AppendAnonymized(myXMLRecFile.NamespaceTag);
                }


                foreach (XMLRecord myRec in myXMLRecFile)
                {
                    XmlDocument doc = new XmlDocument();
                    myRec.MustBeValidatable = true;
                    doc.LoadXml(myRec.getXMLRecord());

                    if (anonymizer != null && nsmgr == null)
                    {
                        nsmgr = new XmlNamespaceManager(doc.NameTable);
                        if (anonymizer.Namespaces.Count > 0)
                        {
                            foreach (string ns in anonymizer.Namespaces)
                            {
                                string[] fields = ns.Split(';');
                                nsmgr.AddNamespace(fields[0], fields[1]);
                                // Console.WriteLine("Naam namespace:'{0}' URL:\t {1}", fields[0], fields[1]);
                            }
                        }
                    }

                    //-------------------------------
                    //Processtype specific coding
                    //--------------------------------
                    if ((Type == ProcessType.AnonymizeToFiles || Type == ProcessType.Anonymize) && anonymizer != null)
                    {
                        //Anonymize the values in the elements to be anonymized
                        foreach (AnonymizeRule rule in anonymizer.AnonymizerRules)
                        {
                            ExceptionMsg = "In file " + _filename + " Xpath that caused exception:\t" + rule.Location;
                            XmlNodeList nodelist = null;

                            if (anonymizer.Namespaces.Count > 0)
                            {
                                nodelist = doc.SelectNodes(rule.Location, nsmgr);
                            }
                            else
                            {
                                nodelist = doc.SelectNodes(rule.Location);
                            }

                            foreach (XmlNode myNode in nodelist)
                            {
                                string nodeValue = myNode.InnerXml;
                                //Some anonymizations are filtered. They require handling by a different function
                                if (rule.IsFiltered)
                                {
                                    XmlNode filterNode = null;
                                    if (anonymizer.Namespaces.Count > 0)
                                    {
                                        filterNode = doc.SelectSingleNode(rule.FilterLocation, nsmgr);
                                    }
                                    else
                                    {
                                        filterNode = doc.SelectSingleNode(rule.FilterLocation);
                                    }
                                    myNode.InnerXml = anonymizer.ProcessFilter(rule, nodeValue, filterNode.InnerXml);
                                }
                                else
                                {
                                    myNode.InnerXml = anonymizer.Anonymize(nodeValue, rule.Method);
                                }

                                //if a filename contains the value of an element, it must be anonymized too
                                if (_anonymized_filename.Length == 0)
                                {
                                    _anonymized_filename = _filename;
                                }

                                //In the code the filename is also anonymized.
                                //First this was implemented by recognizing if there was a value to be anonymized
                                // but this wasn't precise enough and to unwanted modifications in the filename
                                //By introducing a filename rule, an extra criteria, namely the
                                //elementname with the value to be anonymized, could be added
                                bool found = false;
                                foreach (String filenameRule in anonymizer.AnonymizerRulesFilename)
                                {
                                    if (filenameRule.Equals(myNode.Name))
                                    {
                                        found = true;
                                        break;
                                    }
                                }
                                if (_filename.IndexOf(nodeValue) > 0 && found)
                                {
                                    _anonymized_filename = _anonymized_filename.Replace(nodeValue, myNode.InnerXml);
                                }
                            }
                        }
                    }

                    if (Type == ProcessType.ToMemory)
                    {
                        XMLRecordList.Add(myRec);
                    }
                    if (Type == ProcessType.ToFile || Type == ProcessType.AnonymizeToFiles)
                    {
                        this.Write(myRec, Type);
                        //count of written files
                        i++;
                    }

                    if (Type == ProcessType.Anonymize)
                    {
                        myRec.MustBeValidatable = false;
                        string xmlText = myRec.getXMLRecord();
                        AppendAnonymized(xmlText);
                    }
                } // foreach

                //Processtype specific output
                if (Type == ProcessType.ToFile)
                {
                    Console.WriteLine("{0} bestanden met 1 XMLRecord aangemaakt uit bestand {1} met containertag {2}."
                                      , i, _filename, _containerTags[0]);
                }

                if (Type == ProcessType.AnonymizeToFiles)
                {
                    Console.WriteLine("{0} bestanden geanonimiseerd ({3} anonimiseer regels) en aangemaakt uit bestand {1} met containertag {2}."
                                      , i, _filename, _containerTags[0], anonymizer.AnonymizerRules.Count);
                }

                if (Type == ProcessType.Anonymize)
                {
                    AppendAnonymized(myXMLRecFile.EndNamespaceTag);
                    if (_anonymized_filename.Length == 0)
                    {
                        output_anonymized_filename = _filename;
                    }
                    else
                    {
                        output_anonymized_filename = _anonymized_filename;
                    }

                    output_anonymized_filename = String.Concat(output_anonymized_filename, String.Concat(anonymous, postfix));
                    //Rename the tempfile to the anonymized filename
                    if (File.Exists(output_anonymized_filename))
                    {
                        File.Delete(output_anonymized_filename);
                    }
                    File.Move(tempfile, output_anonymized_filename);
                    Console.WriteLine("bestand {0} contains the anonymized data of {1}", output_anonymized_filename, _filename);
                }

                if (Type == ProcessType.ToMemory)
                {
                    XMLRecordList.Sort();
                }
            } catch (Exception e) {
                throw new XmlException(String.Concat(ExceptionMsg, "\r\n", e.ToString()));
            }
        }