Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 7-Oct-12 5:21am
Edited 7-Oct-12 5:22am
v2
Comments
OriginalGriff at 7-Oct-12 11:28am
   
What error or problem do you get?
Mayur2258 at 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. ?
Milind Thakkar at 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)

  Print Answers RSS
0 Maciej Los 450
1 OriginalGriff 403
2 CPallini 189
3 Sergey Alexandrovich Kryukov 189
4 CHill60 180
0 OriginalGriff 6,092
1 Sergey Alexandrovich Kryukov 4,958
2 Maciej Los 3,269
3 Peter Leow 3,129
4 DamithSL 2,490


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 7 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100