C# Using XmlTextWriter, XmlTextReader with multiple elements
===

I use with C# 2008 Net Framework 3.5 the System.Xml Namespace. There are two functions XmlTextReader and XmlTextWriter which I use. The writing succeeds already, but I can't get SPECIFIC information back without reading the whole file. The file will be 5 GB+ size in the end, so I would like to directly call a section instead of reading each time the whole file to search a specific section or id. Binary information will be stored as text inside of some elements. this is only a demo file.

My attempt to read a specific sections information of the example file (doesn't work!)
without going from start to the end in the whole file for searching a section.

    private void button4_Click(object sender, EventArgs e)
        {
            XmlReader reader = new XmlTextReader("C:\\test\\cache.xml");
            reader.ReadStartElement("Cache");
            reader.ReadStartElement("C:\\Windows\\epplauncher.mif"); //go to the first element with the specific key
            string Tmp=reader.ReadElementContentAsString("id", "");
            reader.ReadEndElement(); //read end of element to close the reading on the tag
            reader.Close();
            textBox1.Text = Tmp;
        }

My example code to write the file (succeeds):

    private void button3_Click(object sender, EventArgs e)
        {
            XmlTextWriter writer = new XmlTextWriter("C:\\test\\cache.xml", null);  //Write the root element
            writer.Formatting = Formatting.Indented; //Use automatic indentation for readability

            string[] tmp=Directory.GetFiles("C:\\Windows", "*.*", SearchOption.TopDirectoryOnly);

            writer.WriteStartElement("Cache");   //Write the root element
            int i = 0;
            foreach (string file1 in tmp)
            {
                
                writer.WriteStartElement(file1);          //Write sub-elements
                writer.WriteElementString("id", new FileInfo(file1).Length.ToString());
                writer.WriteElementString("title", Path.GetFileName(file1));
                writer.WriteElementString("description", new FileInfo(file1).Attributes.ToString());
                writer.WriteElementString("ImageX", "Image" + i++.ToString());  // end the root element20.
                writer.WriteEndElement();                                      //Write the XML to file and close the writer
            }
            
            writer.WriteFullEndElement(); // end the root element
            writer.Close(); //Write the XML to file and close the writer     
        }

My example XML file:

My exmaple xml I could not post, xml not accepted here.