//------< make query into current file set >-----------
        private void xmlQuery(string[] args, string path, bool matchAll)
        {
            bool exist;
            //judge is that every text file has a associate matadata file
            List <string> textfiles = new List <string>();
            List <string> xmlfiles  = new List <string>();

            string[] files = Directory.GetFiles(path);
            textfiles.Clear();//clear container for recursion function
            xmlfiles.Clear();
            foreach (string file in files)
            {
                try
                {
                    TextFile tf = new TextFile();
                    if (tf.textFile(Path.GetExtension(file)))
                    {
                        textfiles.Add(file);
                    }
                    else if (Path.GetExtension((file)) == ".xml")
                    {
                        xmlfiles.Add(file);
                    }
                }
                catch
                {
                    Console.Write("\n Error processing {0}", file);
                }
            }
            //find associate xml file for each text file by compare name
            foreach (string textfile in textfiles)
            {
                exist = false;
                foreach (string xmlfile in xmlfiles)
                {
                    if (xmlfile == textfile + ".xml")
                    {
                        exist = true;
                        LinqToXml ltx = new LinqToXml();
                        ltx.linqToXml(args, xmlfile);
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
                //text file doesn't have a associate xml file
                if (!exist)
                {
                    errfiles.Add(textfile);
                }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            Console.Write("\n Test LinqToXml");
            Console.Write("\n================\n");

            List <string> xmlfiles = new List <string>();
            LinqToXml     ltx      = new LinqToXml();
            string        path     = args[0];

            string[] files = Directory.GetFiles(path);
            foreach (string file in files)
            {
                if (Path.GetExtension((file)) == ".xml")
                {
                    xmlfiles.Add(file);
                }
            }
            foreach (string xmlfile in xmlfiles)
            {
                Console.Write("\n{0}\n", xmlfile);
            }

            ltx.linqToXml(args, xmlfiles);
        }