/// <summary> /// /// </summary> /// <returns></returns> public int DoWork() { var knights = _out.Element("knights"); SingletonKnightParser.LoadWbXml(_wbPathAndFilename); IEnumerable <XElement> allElements = from el in _ksRelationshipsXml.Elements() select el; List <XElement> allTheKnights = new List <XElement>(); foreach (var element in allElements) { if (element.Name != "knight") { continue; } var knight = SingletonKnightParser.Parse(element); allTheKnights.Add(knight); knights?.Add(knight); } using (var file = new StreamWriter(_outPathAndFilename)) { const string doubleQuote = "\""; const string xmlHeader = @"<?xml version=" + doubleQuote + "1.0" + doubleQuote + " encoding=" + doubleQuote + "utf-8" + doubleQuote + "?>"; file.WriteLine(xmlHeader); const string knightsStart = "<knights>"; file.WriteLine(knightsStart); foreach (string line in allTheKnights.Select(knightElement => knightElement.ToString())) { file.WriteLine(line); } const string knightsEnd = "</knights>"; file.WriteLine(knightsEnd); } Debug.WriteLine("****************** [[[ FINISHED ]]] ******************"); return(0); }
/// <summary> /// /// </summary> /// <returns></returns> public int DoWork() { Debug.WriteLine("MergeJob.DoWork() ..."); const string xmlheader1 = @"<?xml version=""1.0"" encoding=""utf-8""?>"; _fileStringBuilder.Append(xmlheader1); _fileStringBuilder.Append("<knights>"); var root = _ksRelationshipsXml.DocumentElement; SingletonKnightParser.LoadWbXml(_wbPathAndFilename); foreach (XmlNode rootChild in root.ChildNodes) { if (rootChild.LocalName != "knight") { continue; } var xD = new XmlDocument(); xD.LoadXml(rootChild.OuterXml); var rKnightNode = xD.FirstChild; var newKnightStringBuilder = SingletonKnightParser.Parse(rKnightNode); _fileStringBuilder.Append(newKnightStringBuilder); } _fileStringBuilder.Append("</knights>"); using (var swriter = new StreamWriter(_outPathAndFilename)) { swriter.Write(_fileStringBuilder.ToString()); } Debug.WriteLine("****************** [[[ FINISHED ]]] ******************"); return(0); }