public XmlSplitter(XmlTagsList tags, string splitTag) { //split tags foreach (XmlTag tag in tags.tagsList) { if (tag.element.Name.ToString() == splitTag) { parts.Add(currentPart); currentPart = new List <XmlTag>(); } else { currentPart.Add(tag); } } //end parts.Add(currentPart); //reform a doc from every part foreach (List <XmlTag> part in parts) { if (part.Count == 0) { continue; } // outFiles.Add(formDocument(part)); } }
static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Yellow; if (args.Length == 0) { Console.WriteLine("no files passed"); } else { Console.WriteLine("what's the name of the element you want to split on?"); string splitTag = Console.ReadLine(); foreach (string filePath in args) { try { //extract tags XmlTagsList tagsList = new XmlTagsList(filePath); // new XmlSplitter(tagsList, splitTag).writeOutputFiles(filePath); // Console.WriteLine("\r\nfile: " + filePath); Console.WriteLine("completed successfully \r\n"); } catch (Exception exp) { Console.WriteLine("\r\nERROR in file: " + filePath); Console.WriteLine(exp); Console.WriteLine(exp.Message); } } } //keep console open Console.WriteLine("Press any key to close..."); Console.ReadKey(); }