public GenericXmlReaderResults ProcessFile(string XmlFile, string MappingFile)
        {
            // Open the mapping file first
            GenericXmlMappingSet set = GenericXmlMappingSet.Read(MappingFile);

            // Return value
            GenericXmlReaderResults returnValue = new GenericXmlReaderResults();

            // Stack to keep all the parent nodes
            Stack <GenericXmlNode> currentStack = new Stack <GenericXmlNode>();

            try
            {
                // Get the XML file content, stripped of display tags
                string content = cleaned_xml_string_from_file(XmlFile, set);

                // Streams used for reading
                XmlTextReader readerXml = new XmlTextReader(new StringReader(content));

                // Step through the top-level elements
                while (readerXml.Read())
                {
                    if (readerXml.NodeType == XmlNodeType.Element)
                    {
                        // Create the node for this top-level element
                        string         nodeName = readerXml.Name;
                        GenericXmlNode topNode  = new GenericXmlNode {
                            NodeName = nodeName
                        };

                        // Add this to the stack
                        currentStack.Push(topNode);

                        // Recursively read this and all children
                        recursive_process_file(readerXml.ReadSubtree(), currentStack, set, returnValue);

                        // Since this node was handled, pop it off the stack
                        currentStack.Pop();
                    }
                }
            }
            catch (Exception ee)
            {
                returnValue.ErrorMessage = ee.Message;
            }

            return(returnValue);
        }
        public List <GenericXmlPath> GetExistingPaths(string XmlFile)
        {
            // Streams used for reading
            Stream        readerStream = null;
            XmlTextReader readerXml    = null;

            // Return value
            Dictionary <string, string> pathExistenceCheck = new Dictionary <string, string>();
            List <GenericXmlPath>       returnValue        = new List <GenericXmlPath>();
            Stack <GenericXmlNode>      currentStack       = new Stack <GenericXmlNode>();

            try
            {
                // Open a link to the file
                readerStream = new FileStream(XmlFile, FileMode.Open, FileAccess.Read);

                // Try to read the XML
                readerXml = new XmlTextReader(readerStream);

                // Step through the top-level elements
                while (readerXml.Read())
                {
                    if (readerXml.NodeType == XmlNodeType.Element)
                    {
                        // Create the node for this top-level element
                        string         nodeName = readerXml.Name;
                        GenericXmlNode topNode  = new GenericXmlNode {
                            NodeName = nodeName
                        };

                        // Add this to the stack
                        currentStack.Push(topNode);

                        // Recursively read this and all children
                        recursive_get_existing_paths(readerXml.ReadSubtree(), currentStack, pathExistenceCheck, returnValue);

                        // Since this node was handled, pop it off the stack
                        currentStack.Pop();
                    }
                }
            }
            catch
            {
                // MessageBox.Show(ee.Message);
            }

            return(returnValue);
        }
        public List <GenericXmlPathValue> GetMappedValues(string XmlFile, string MappingFile)
        {
            // Open the mapping file first
            GenericXmlMappingSet set = GenericXmlMappingSet.Read(MappingFile);

            // Return value
            List <GenericXmlPathValue> returnValue  = new List <GenericXmlPathValue>();
            Stack <GenericXmlNode>     currentStack = new Stack <GenericXmlNode>();

            try
            {
                // Get the XML file content, stripped of display tags
                string content = cleaned_xml_string_from_file(XmlFile, set);

                // Streams used for reading
                XmlTextReader readerXml = new XmlTextReader(new StringReader(content));

                // Step through the top-level elements
                while (readerXml.Read())
                {
                    if (readerXml.NodeType == XmlNodeType.Element)
                    {
                        // Create the node for this top-level element
                        string         nodeName = readerXml.Name;
                        GenericXmlNode topNode  = new GenericXmlNode {
                            NodeName = nodeName
                        };

                        // Add this to the stack
                        currentStack.Push(topNode);

                        // Recursively read this and all children
                        recursive_get_mapped_values(readerXml.ReadSubtree(), currentStack, returnValue, set);

                        // Since this node was handled, pop it off the stack
                        currentStack.Pop();
                    }
                }
            }
            catch
            {
                // MessageBox.Show(ee.Message);
            }

            return(returnValue);
        }
        private void recursive_process_file(XmlReader readerXml, Stack<GenericXmlNode> currentStack, GenericXmlMappingSet set, GenericXmlReaderResults returnValue)
        {
            // Create the list of nodes to this point from the stack
            List<GenericXmlNode> currentReverseList = currentStack.ToList();

            // THis is now on THIS element, so move to the next, unless there were none
            if (!readerXml.Read()) return;

            // Create the path for this
            GenericXmlPath currentPath = new GenericXmlPath();
            for (int j = currentReverseList.Count - 1; j >= 0; j--)
            {
                currentPath.PathNodes.Add(currentReverseList[j]);
            }

            //// First, handle any attributes
            //if (readerXml.HasAttributes)
            //{
            //    // Create the list of nodes to this point
            //    for (int i = 0; i < readerXml.AttributeCount; i++)
            //    {
            //        // Move to this attribute
            //        readerXml.MoveToAttribute(i);

            //        // Create the path for this
            //        GenericXmlPath thisPath = new GenericXmlPath();
            //        for (int j = currentReverseList.Count - 1; j >= 0; j--)
            //        {
            //            thisPath.PathNodes.Add(currentReverseList[j]);
            //        }
            //        thisPath.AttributeName = readerXml.Name;

            //        // Get the value for this path
            //        string attributeValue = readerXml.Value;

            //        // Does mapping exist for this path?
            //        PathMappingInstructions instructions = set.Get_Matching_Path_Instructions(thisPath);

            //        // If instructions, this was mapped
            //        if ((instructions != null) && (!String.IsNullOrEmpty(instructions.SobekMapping)))
            //        {
            //            MappedValue thisMappedValue = new MappedValue();
            //            thisMappedValue.Mapping = instructions.SobekMapping;
            //            thisMappedValue.Path = thisPath;
            //            thisMappedValue.Value = attributeValue;

            //            returnValue.MappedValues.Add(thisMappedValue);
            //        }
            //    }

            //    // Move back to the main element after handing the attributes
            //    readerXml.MoveToElement();
            //}

            // Now, iterate through all the child elements that may exist
            while (readerXml.Read())
            {
                //if (readerXml.NodeType == XmlNodeType.Text)
                //{
                //    // Create the path for this
                //    GenericXmlPath thisPath = new GenericXmlPath();
                //    for (int j = currentReverseList.Count - 1; j >= 0; j--)
                //    {
                //        thisPath.PathNodes.Add(currentReverseList[j]);
                //    }

                //    // Does mapping exist for this path?
                //    PathMappingInstructions instructions = set.Get_Matching_Path_Instructions(thisPath);

                //    // Get the value for this path
                //    string textValue = readerXml.Value;

                //    // If instructions, this was mapped
                //    if ((instructions != null) && ( !String.IsNullOrEmpty(instructions.SobekMapping)))
                //    {
                //        MappedValue thisMappedValue = new MappedValue();
                //        thisMappedValue.Mapping = instructions.SobekMapping;
                //        thisMappedValue.Path = thisPath;
                //        thisMappedValue.Value = textValue;

                //        returnValue.MappedValues.Add(thisMappedValue);
                //    }
                //}

                bool text_found = false;
                if (readerXml.NodeType == XmlNodeType.Element)
                {
                    // Create the node for this top-level element
                    string nodeName = readerXml.Name;
                    GenericXmlNode topNode = new GenericXmlNode { NodeName = nodeName };

                    // Add this to the stack
                    currentStack.Push(topNode);

                    if (topNode.NodeName == "text")
                        text_found = true;

                    // It may be that mapping exists right here at this level
                    // Create the path for this
                    currentReverseList = currentStack.ToList();
                    GenericXmlPath thisPath = new GenericXmlPath();
                    for (int j = currentReverseList.Count - 1; j >= 0; j--)
                    {
                        thisPath.PathNodes.Add(currentReverseList[j]);
                    }

                    // Does mapping exist for this path?
                    if (set.Contains_Path(thisPath))
                    {
                        // Collect the attributes FIRST
                        List<Tuple<string, string>> attributes = null;
                        if (readerXml.HasAttributes)
                        {
                            attributes = new List<Tuple<string, string>>();
                            readerXml.MoveToFirstAttribute();
                            attributes.Add(new Tuple<string, string>(readerXml.Name, readerXml.Value));
                            while (readerXml.MoveToNextAttribute())
                            {
                                attributes.Add(new Tuple<string, string>(readerXml.Name, readerXml.Value));
                            }
                            readerXml.MoveToElement();
                        }

                        // Does mapping exist for this path?
                        PathMappingInstructions instructions = set.Get_Matching_Path_Instructions(thisPath);

                        // If instructions, this was mapped
                        if ((instructions != null) && (!String.IsNullOrEmpty(instructions.SobekMapping)) && (instructions.IgnoreSubTree))
                        {
                            MappedValue thisMappedValue = new MappedValue();
                            thisMappedValue.Mapping = instructions.SobekMapping;
                            thisMappedValue.Path = thisPath;

                            if (instructions.RetainInnerXmlTags)
                            {
                                thisMappedValue.Value = readerXml.ReadInnerXml();
                            }
                            else
                            {
                                StringBuilder builder = new StringBuilder();
                                XmlReader innerReader = readerXml.ReadSubtree();
                                while (innerReader.Read())
                                {
                                    if (innerReader.NodeType == XmlNodeType.Text)
                                    {
                                        builder.Append(innerReader.Value);
                                    }
                                }
                                thisMappedValue.Value = builder.ToString();
                            }

                            returnValue.MappedValues.Add(thisMappedValue);

                            //// Actually, there is something here about skipping this
                            //readerXml.Skip();
                        }
                        else
                        {
                            // Recursively read this and all children
                            recursive_process_file(readerXml.ReadSubtree(), currentStack, set, returnValue);
                        }

                        // Now, handle the attributes
                        if ((attributes != null) && (attributes.Count > 0))
                        {
                            foreach (Tuple<string, string> attribute in attributes)
                            {
                                // Does mapping exist for this path?
                                PathMappingInstructions attrInstructions = set.Get_Matching_Path_Instructions(thisPath, attribute.Item1);

                                // If instructions, this was mapped
                                if ((attrInstructions != null) && (!String.IsNullOrEmpty(attrInstructions.SobekMapping)))
                                {
                                    MappedValue thisMappedValue = new MappedValue();
                                    thisMappedValue.Mapping = attrInstructions.SobekMapping;
                                    thisMappedValue.Path = thisPath;
                                    thisMappedValue.Path.AttributeName = attribute.Item1;
                                    thisMappedValue.Value = attribute.Item2;

                                    returnValue.MappedValues.Add(thisMappedValue);
                                }
                            }
                        }
                    }

                    // Since this node was handled, pop it off the stack
                    currentStack.Pop();
                }
            }
        }
        private void recursive_get_values(XmlReader readerXml, Stack<GenericXmlNode> currentStack, List<GenericXmlPathValue> returnValue)
        {
            // Create the list of nodes to this point from the stack
            List<GenericXmlNode> currentReverseList = currentStack.ToList();

            // THis is now on THIS element, so move to the next, unless there were none
            if (!readerXml.Read()) return;

            // Check to see if this node has been added yet
            // Create the path for this
            GenericXmlPath currentPath = new GenericXmlPath();
            for (int j = currentReverseList.Count - 1; j >= 0; j--)
            {
                currentPath.PathNodes.Add(currentReverseList[j]);
            }

            //// Was this already added?
            //string currentPathString = currentPath.ToString();
            //if (!pathExistenceCheck.ContainsKey(currentPathString))
            //{
            //    pathExistenceCheck[currentPathString] = currentPathString;
            //    returnValue.Add(currentPath);
            //}

            // First, handle any attributes
            if (readerXml.HasAttributes)
            {
                // Create the list of nodes to this point
                for (int i = 0; i < readerXml.AttributeCount; i++)
                {
                    // Move to this attribute
                    readerXml.MoveToAttribute(i);

                    // Create the path for this
                    GenericXmlPath thisPath = new GenericXmlPath();
                    for (int j = currentReverseList.Count - 1; j >= 0; j--)
                    {
                        thisPath.PathNodes.Add(currentReverseList[j]);
                    }
                    thisPath.AttributeName = readerXml.Name;

                    // Get the value for this path
                    string attributeValue = readerXml.Value;

                    // Add this path/value pair to the return value
                    returnValue.Add(new GenericXmlPathValue(thisPath, attributeValue));
                }

                // Move back to the main element after handing the attributes
                readerXml.MoveToElement();
            }

            //// THis is now on THIS element, so move to the next, unless there were none
            //if (!readerXml.Read()) return;

            //// Is there actual text for this element
            //if ( !String.IsNullOrEmpty(readerXml.Value))
            //{
            //    // Create the path for this
            //    GenericXmlReaderMapperPath thisPath = new GenericXmlReaderMapperPath();
            //    for (int j = currentReverseList.Count - 1; j >= 0; j--)
            //    {
            //        thisPath.PathNodes.Add(currentReverseList[j]);
            //    }

            //    // Was this already added?
            //    string pathString = thisPath.ToString();
            //    if (!pathExistenceCheck.ContainsKey(pathString))
            //    {
            //        pathExistenceCheck[pathString] = pathString;
            //        returnValue.Add(thisPath);
            //    }
            //}

            // Now, iterate through all the child elements that may exist
            while (readerXml.Read())
            {
                if (readerXml.NodeType == XmlNodeType.Text)
                {
                    // Create the path for this
                    GenericXmlPath thisPath = new GenericXmlPath();
                    for (int j = currentReverseList.Count - 1; j >= 0; j--)
                    {
                        thisPath.PathNodes.Add(currentReverseList[j]);
                    }

                    // Get the value for this path
                    string textValue = readerXml.Value;

                    // Add this path/value pair to the return value
                    returnValue.Add(new GenericXmlPathValue(thisPath, textValue));
                }

                if (readerXml.NodeType == XmlNodeType.Element)
                {
                    // Create the node for this top-level element
                    string nodeName = readerXml.Name;
                    GenericXmlNode topNode = new GenericXmlNode { NodeName = nodeName };

                    // Add this to the stack
                    currentStack.Push(topNode);

                    // Recursively read this and all children
                    recursive_get_values(readerXml.ReadSubtree(), currentStack, returnValue);

                    // Since this node was handled, pop it off the stack
                    currentStack.Pop();
                }
            }
        }
        public GenericXmlReaderResults ProcessFile(string XmlFile, string MappingFile)
        {
            // Open the mapping file first
            GenericXmlMappingSet set = GenericXmlMappingSet.Read(MappingFile);

            // Return value
            GenericXmlReaderResults returnValue = new GenericXmlReaderResults();

            // Stack to keep all the parent nodes
            Stack<GenericXmlNode> currentStack = new Stack<GenericXmlNode>();

            try
            {
                // Get the XML file content, stripped of display tags
                string content = cleaned_xml_string_from_file(XmlFile, set);

                // Streams used for reading
                XmlTextReader readerXml = new XmlTextReader(new StringReader(content));

                // Step through the top-level elements
                while (readerXml.Read())
                {
                    if (readerXml.NodeType == XmlNodeType.Element)
                    {
                        // Create the node for this top-level element
                        string nodeName = readerXml.Name;
                        GenericXmlNode topNode = new GenericXmlNode { NodeName = nodeName };

                        // Add this to the stack
                        currentStack.Push(topNode);

                        // Recursively read this and all children
                        recursive_process_file(readerXml.ReadSubtree(), currentStack, set, returnValue);

                        // Since this node was handled, pop it off the stack
                        currentStack.Pop();

                    }
                }

            }
            catch (Exception ee)
            {
                returnValue.ErrorMessage = ee.Message;
            }

            return returnValue;
        }
        public List<GenericXmlPathValue> GetValues(string XmlFile, string MappingFile )
        {
            // Open the mapping file first
            GenericXmlMappingSet set = GenericXmlMappingSet.Read(MappingFile);

            // Return value
            List<GenericXmlPathValue> returnValue = new List<GenericXmlPathValue>();
            Stack<GenericXmlNode> currentStack = new Stack<GenericXmlNode>();

            try
            {
                // Get the XML file content, stripped of display tags
                string content = cleaned_xml_string_from_file(XmlFile, set);

                // Streams used for reading
                XmlTextReader readerXml = new XmlTextReader(new StringReader(content));

                // Step through the top-level elements
                while (readerXml.Read())
                {
                    if (readerXml.NodeType == XmlNodeType.Element)
                    {
                        // Create the node for this top-level element
                        string nodeName = readerXml.Name;
                        GenericXmlNode topNode = new GenericXmlNode { NodeName = nodeName };

                        // Add this to the stack
                        currentStack.Push(topNode);

                        // Recursively read this and all children
                        recursive_get_values(readerXml.ReadSubtree(), currentStack, returnValue);

                        // Since this node was handled, pop it off the stack
                        currentStack.Pop();

                    }
                }

            }
            catch
            {
                // MessageBox.Show(ee.Message);
            }

            return returnValue;
        }
        public List<GenericXmlPath> GetExistingPaths(string XmlFile)
        {
            // Streams used for reading
            Stream readerStream = null;
            XmlTextReader readerXml = null;

            // Return value
            Dictionary<string, string> pathExistenceCheck = new Dictionary<string, string>();
            List<GenericXmlPath> returnValue = new List<GenericXmlPath>();
            Stack<GenericXmlNode> currentStack = new Stack<GenericXmlNode>();

            try
            {
                // Open a link to the file
                readerStream = new FileStream(XmlFile, FileMode.Open, FileAccess.Read);

                // Try to read the XML
                readerXml = new XmlTextReader(readerStream);

                // Step through the top-level elements
                while (readerXml.Read())
                {
                    if (readerXml.NodeType == XmlNodeType.Element)
                    {
                        // Create the node for this top-level element
                        string nodeName = readerXml.Name;
                        GenericXmlNode topNode = new GenericXmlNode {NodeName = nodeName};

                        // Add this to the stack
                        currentStack.Push(topNode);

                        // Recursively read this and all children
                        recursive_get_existing_paths(readerXml.ReadSubtree(), currentStack, pathExistenceCheck, returnValue);

                        // Since this node was handled, pop it off the stack
                        currentStack.Pop();

                    }
                }

            }
            catch
            {
               // MessageBox.Show(ee.Message);
            }

            return returnValue;
        }
        private void recursive_get_existing_paths(XmlReader readerXml, Stack <GenericXmlNode> currentStack, Dictionary <string, string> pathExistenceCheck, List <GenericXmlPath> returnValue)
        {
            // Create the list of nodes to this point from the stack
            List <GenericXmlNode> currentReverseList = currentStack.ToList();


            // THis is now on THIS element, so move to the next, unless there were none
            if (!readerXml.Read())
            {
                return;
            }

            // Check to see if this node has been added yet
            // Create the path for this
            GenericXmlPath currentPath = new GenericXmlPath();

            for (int j = currentReverseList.Count - 1; j >= 0; j--)
            {
                currentPath.PathNodes.Add(currentReverseList[j]);
            }

            // Was this already added?
            string currentPathString = currentPath.ToString();

            if (!pathExistenceCheck.ContainsKey(currentPathString))
            {
                pathExistenceCheck[currentPathString] = currentPathString;
                returnValue.Add(currentPath);
            }

            // First, handle any attributes
            if (readerXml.HasAttributes)
            {
                // Create the list of nodes to this point
                for (int i = 0; i < readerXml.AttributeCount; i++)
                {
                    // Move to this attribute
                    readerXml.MoveToAttribute(i);

                    // Create the path for this
                    GenericXmlPath thisPath = new GenericXmlPath();
                    for (int j = currentReverseList.Count - 1; j >= 0; j--)
                    {
                        thisPath.PathNodes.Add(currentReverseList[j]);
                    }
                    thisPath.AttributeName = readerXml.Name;

                    // Was this already added?
                    string pathString = thisPath.ToString();
                    if (!pathExistenceCheck.ContainsKey(pathString))
                    {
                        pathExistenceCheck[pathString] = pathString;
                        returnValue.Add(thisPath);
                    }
                }

                // Move back to the main element after handing the attributes
                readerXml.MoveToElement();
            }

            //// THis is now on THIS element, so move to the next, unless there were none
            //if (!readerXml.Read()) return;



            //// Is there actual text for this element
            //if ( !String.IsNullOrEmpty(readerXml.Value))
            //{
            //    // Create the path for this
            //    GenericXmlReaderMapperPath thisPath = new GenericXmlReaderMapperPath();
            //    for (int j = currentReverseList.Count - 1; j >= 0; j--)
            //    {
            //        thisPath.PathNodes.Add(currentReverseList[j]);
            //    }

            //    // Was this already added?
            //    string pathString = thisPath.ToString();
            //    if (!pathExistenceCheck.ContainsKey(pathString))
            //    {
            //        pathExistenceCheck[pathString] = pathString;
            //        returnValue.Add(thisPath);
            //    }
            //}



            // Now, iterate through all the child elements that may exist
            while (readerXml.Read())
            {
                if (readerXml.NodeType == XmlNodeType.Text)
                {
                    // Create the path for this
                    GenericXmlPath thisPath = new GenericXmlPath();
                    for (int j = currentReverseList.Count - 1; j >= 0; j--)
                    {
                        thisPath.PathNodes.Add(currentReverseList[j]);
                    }

                    // Was this already added?
                    string pathString = thisPath.ToString();
                    if (!pathExistenceCheck.ContainsKey(pathString))
                    {
                        pathExistenceCheck[pathString] = pathString;
                        returnValue.Add(thisPath);
                    }
                }

                if (readerXml.NodeType == XmlNodeType.Element)
                {
                    // Create the node for this top-level element
                    string         nodeName = readerXml.Name;
                    GenericXmlNode topNode  = new GenericXmlNode {
                        NodeName = nodeName
                    };

                    // Add this to the stack
                    currentStack.Push(topNode);

                    // Recursively read this and all children
                    recursive_get_existing_paths(readerXml.ReadSubtree(), currentStack, pathExistenceCheck, returnValue);

                    // Since this node was handled, pop it off the stack
                    currentStack.Pop();
                }
            }
        }
        private void recursive_process_file(XmlReader readerXml, Stack <GenericXmlNode> currentStack, GenericXmlMappingSet set, GenericXmlReaderResults returnValue)
        {
            // Create the list of nodes to this point from the stack
            List <GenericXmlNode> currentReverseList = currentStack.ToList();

            // THis is now on THIS element, so move to the next, unless there were none
            if (!readerXml.Read())
            {
                return;
            }

            // Create the path for this
            GenericXmlPath currentPath = new GenericXmlPath();

            for (int j = currentReverseList.Count - 1; j >= 0; j--)
            {
                currentPath.PathNodes.Add(currentReverseList[j]);
            }

            //// First, handle any attributes
            //if (readerXml.HasAttributes)
            //{
            //    // Create the list of nodes to this point
            //    for (int i = 0; i < readerXml.AttributeCount; i++)
            //    {
            //        // Move to this attribute
            //        readerXml.MoveToAttribute(i);

            //        // Create the path for this
            //        GenericXmlPath thisPath = new GenericXmlPath();
            //        for (int j = currentReverseList.Count - 1; j >= 0; j--)
            //        {
            //            thisPath.PathNodes.Add(currentReverseList[j]);
            //        }
            //        thisPath.AttributeName = readerXml.Name;

            //        // Get the value for this path
            //        string attributeValue = readerXml.Value;

            //        // Does mapping exist for this path?
            //        PathMappingInstructions instructions = set.Get_Matching_Path_Instructions(thisPath);

            //        // If instructions, this was mapped
            //        if ((instructions != null) && (!String.IsNullOrEmpty(instructions.SobekMapping)))
            //        {
            //            MappedValue thisMappedValue = new MappedValue();
            //            thisMappedValue.Mapping = instructions.SobekMapping;
            //            thisMappedValue.Path = thisPath;
            //            thisMappedValue.Value = attributeValue;

            //            returnValue.MappedValues.Add(thisMappedValue);
            //        }
            //    }

            //    // Move back to the main element after handing the attributes
            //    readerXml.MoveToElement();
            //}



            // Now, iterate through all the child elements that may exist
            while (readerXml.Read())
            {
                //if (readerXml.NodeType == XmlNodeType.Text)
                //{
                //    // Create the path for this
                //    GenericXmlPath thisPath = new GenericXmlPath();
                //    for (int j = currentReverseList.Count - 1; j >= 0; j--)
                //    {
                //        thisPath.PathNodes.Add(currentReverseList[j]);
                //    }

                //    // Does mapping exist for this path?
                //    PathMappingInstructions instructions = set.Get_Matching_Path_Instructions(thisPath);

                //    // Get the value for this path
                //    string textValue = readerXml.Value;

                //    // If instructions, this was mapped
                //    if ((instructions != null) && ( !String.IsNullOrEmpty(instructions.SobekMapping)))
                //    {
                //        MappedValue thisMappedValue = new MappedValue();
                //        thisMappedValue.Mapping = instructions.SobekMapping;
                //        thisMappedValue.Path = thisPath;
                //        thisMappedValue.Value = textValue;

                //        returnValue.MappedValues.Add(thisMappedValue);
                //    }
                //}

                bool text_found = false;
                if (readerXml.NodeType == XmlNodeType.Element)
                {
                    // Create the node for this top-level element
                    string         nodeName = readerXml.Name;
                    GenericXmlNode topNode  = new GenericXmlNode {
                        NodeName = nodeName
                    };

                    // Add this to the stack
                    currentStack.Push(topNode);

                    if (topNode.NodeName == "text")
                    {
                        text_found = true;
                    }

                    // It may be that mapping exists right here at this level
                    // Create the path for this
                    currentReverseList = currentStack.ToList();
                    GenericXmlPath thisPath = new GenericXmlPath();
                    for (int j = currentReverseList.Count - 1; j >= 0; j--)
                    {
                        thisPath.PathNodes.Add(currentReverseList[j]);
                    }

                    // Does mapping exist for this path?
                    if (set.Contains_Path(thisPath))
                    {
                        // Collect the attributes FIRST
                        List <Tuple <string, string> > attributes = null;
                        if (readerXml.HasAttributes)
                        {
                            attributes = new List <Tuple <string, string> >();
                            readerXml.MoveToFirstAttribute();
                            attributes.Add(new Tuple <string, string>(readerXml.Name, readerXml.Value));
                            while (readerXml.MoveToNextAttribute())
                            {
                                attributes.Add(new Tuple <string, string>(readerXml.Name, readerXml.Value));
                            }
                            readerXml.MoveToElement();
                        }

                        // Does mapping exist for this path?
                        PathMappingInstructions instructions = set.Get_Matching_Path_Instructions(thisPath);

                        // If instructions, this was mapped
                        if ((instructions != null) && (!String.IsNullOrEmpty(instructions.SobekMapping)) && (instructions.IgnoreSubTree))
                        {
                            MappedValue thisMappedValue = new MappedValue();
                            thisMappedValue.Mapping = instructions.SobekMapping;
                            thisMappedValue.Path    = thisPath;

                            if (instructions.RetainInnerXmlTags)
                            {
                                thisMappedValue.Value = readerXml.ReadInnerXml();
                            }
                            else
                            {
                                StringBuilder builder     = new StringBuilder();
                                XmlReader     innerReader = readerXml.ReadSubtree();
                                while (innerReader.Read())
                                {
                                    if (innerReader.NodeType == XmlNodeType.Text)
                                    {
                                        builder.Append(innerReader.Value);
                                    }
                                }
                                thisMappedValue.Value = builder.ToString();
                            }

                            returnValue.MappedValues.Add(thisMappedValue);

                            //// Actually, there is something here about skipping this
                            //readerXml.Skip();
                        }
                        else
                        {
                            // Recursively read this and all children
                            recursive_process_file(readerXml.ReadSubtree(), currentStack, set, returnValue);
                        }

                        // Now, handle the attributes
                        if ((attributes != null) && (attributes.Count > 0))
                        {
                            foreach (Tuple <string, string> attribute in attributes)
                            {
                                // Does mapping exist for this path?
                                PathMappingInstructions attrInstructions = set.Get_Matching_Path_Instructions(thisPath, attribute.Item1);

                                // If instructions, this was mapped
                                if ((attrInstructions != null) && (!String.IsNullOrEmpty(attrInstructions.SobekMapping)))
                                {
                                    MappedValue thisMappedValue = new MappedValue();
                                    thisMappedValue.Mapping            = attrInstructions.SobekMapping;
                                    thisMappedValue.Path               = thisPath;
                                    thisMappedValue.Path.AttributeName = attribute.Item1;
                                    thisMappedValue.Value              = attribute.Item2;

                                    returnValue.MappedValues.Add(thisMappedValue);
                                }
                            }
                        }
                    }

                    // Since this node was handled, pop it off the stack
                    currentStack.Pop();
                }
            }
        }