Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I am working on XML files. I have created small XML tool which returns number of specific tag repeated in all files.

This code runs properly to find the numbers of tag present in files within specific folder mean there should not be any other folder in XML files containing folder.

I am facing problem if there is any other folder or other type of file present in the XML files containing folder this programs fails.

The code is as follow:

public void SearchMultipleTags()
        {
            if (txtSearchTag.Text != "")
            {
                try
                {
                    //string str = null;
                    //XmlNodeList nodelist;
                    string folderPath = textBox2.Text;
                    DirectoryInfo di = new DirectoryInfo(folderPath);
                    FileInfo[] rgFiles = di.GetFiles("*.xml");
                    foreach (FileInfo fi in rgFiles)
                    {
                        int i = 0;
                        XmlDocument xmldoc = new XmlDocument();
                        xmldoc.Load(fi.FullName);
                        //rtbox2.Text = fi.FullName.ToString();

                        foreach (XmlNode node in xmldoc.GetElementsByTagName(txtSearchTag.Text))
                        {

                            i = i + 1;

                            //
                        }
                        rtbox2.Text += DateTime.Now + "\n" + fi.FullName + " \nInstance: " + i.ToString() + "\n\n";
                        //rtbox2.Text += fi.FullName + "instances: " + str.ToString();
                    }

                }
                catch (Exception)
                {

                    MessageBox.Show("Invalid Path or Empty File name field.");
                }
            }
            else
            {
                MessageBox.Show("Dont leave field blanks.");
            }

        }



Please help in this.

Regards,
Mayur Alaspure.
Posted
Updated 7-Oct-12 5:22am
v2
Comments
OriginalGriff 7-Oct-12 11:28am    
What error or problem do you get?
Mayur2258 7-Oct-12 11:55am    
Hi,

Thanks for response i Checked it again and found that there was an entity text error in XML file thats why the code was failed. Now its working fine.
Thanks again for your interest.. :)

Can you suggest me on following:
My provided Code Search the specific tag in XML files.

Can you suggest me the code to search the specific Text in same XML files. ?
MT_ 8-Oct-12 1:43am    
Mayur,
Please update you post with additional information and your "new" question in order to enable members to help you
Milind

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900