Пример #1
0
        static void Main(string[] args)
        {
            //XmlParser xmlParser = new XmlParser(@"World.xml");
            Rss20 rss20File;


            RssFile rssFile = new RssFile(@"World.xml");

            if (rssFile.rssVersion != RssVersion.v20)
            {
                // Any RSS version that is not RSS 2.0
            }

            Rss20 rss20File = new Rss20(@"World.xml");

            rss20File.PrintXml();

            System.Collections.Generic.List <string> order =
                new System.Collections.Generic.List <string>(new string[]
                                                             { "title",
                                                               "link",
                                                               "description",
                                                               "laguage",
                                                               "copyright",
                                                               "lastBuildDate",
                                                               "image" });

            TableWriter tableWriter = new TableWriter(rssParser, order, "flatfile", 25000, '\t');

            String s = Console.ReadLine();
        }
Пример #2
0
        public TableWriter(RssFile rssF, System.Collections.Generic.List <string> fieldOrder, string fileName, int chunkSize, char columnDelimiter)
        {
            int length;
            int i = 0;

            index           = -1;
            length          = fieldOrder.Count;
            row             = new string[length];
            lineLength      = 0; // length of line
            lineBuilder     = new StringBuilder();
            chunk           = 0;
            linesWritten    = 0;
            filePosition    = 0;
            rowDelimiter    = new char[2];
            rowDelimiter[0] = '\r';
            rowDelimiter[1] = '\n';

            rowDelimiterBytes = new UTF8Encoding(true).GetBytes(rowDelimiter, 0, rowDelimiter.Length);

            this.fieldOrder      = fieldOrder;
            this.fileName        = fileName;
            this.chunkSize       = chunkSize;
            this.columnDelimiter = columnDelimiter;

            CreateNextFlatFileChunk();

            foreach (System.Xml.Linq.XElement xE in rssF.xmlIE)
            {
                try
                {
                    index = fieldOrder.IndexOf(xE.Name.ToString());
                }
                catch (ArgumentNullException e)
                {
                    Console.WriteLine(e.Message);
                }

                if (index == -1)
                {
                    continue;
                }

                row[index] = xE.Value;

                if (i >= length)
                {
                    RowToLine();
                    LineToBytes();
                    WriteLineToFlatFiles();
                    i = 0;
                    continue;
                }

                i++;
            }
        }