public XmlNode GetXmlTable(XmlDocument document, TagToReplace currentTagToReplace, int applicationId) { XmlTableCreate xmlTableCreate = new XmlTableCreate(); List <List <string> > newNestedList = GetNestedDataList(currentTagToReplace.ReplacemantList, applicationId); if (newNestedList == null) { return(null); } XmlNode newXmlTableNode = xmlTableCreate.GetXmlTable(document, newNestedList, false); return(newXmlTableNode); }
public bool CreateDocument(string templatePath, string newFilePath, int applicationId, int documentType) { #region создаем экземпляры нужных классов XmlTableCreate xmlTableCreate = new XmlTableCreate(); #endregion #region открываем шаблон string xmlFile = File.ReadAllText(templatePath); XmlDocument document = new XmlDocument(); document.LoadXml(xmlFile); #endregion #region старый вариант /* * List<zColumnTable> columnListWithUniqueMark = FindColumnsWithUniqueMarkExist(applicationId); * foreach (zColumnTable currentColumn in columnListWithUniqueMark) * { * xmlFile = xmlFile.Replace(currentColumn.UniqueMark, FindValue(currentColumn, applicationId)); * }*/ #endregion XmlNode sectNode = FindNode(document.ChildNodes, "wx:sect"); //нам нужен список того в файле что нужно заменить) // пока что 2 вхождения ищем //1) #Table* заменяем весь ноде после секции //2) #Line* заменяем только значение нода TagsToReplace tagsToReplaceClass = new TagsToReplace(); CreateXmlTable createXmlTableClass = new CreateXmlTable(); List <TagToReplace> tagsToReplaces = tagsToReplaceClass.GetTagsToReplace(document); //мы получили список того что нужно заменить #region поочереди заменяем foreach (TagToReplace currentTagToReplace in tagsToReplaces) { if (currentTagToReplace.ReplaceType == 2) { XmlNode newXmlNode = createXmlTableClass.GetXmlTable(document, currentTagToReplace, applicationId); if (newXmlNode != null) { document.ImportNode(newXmlNode, true); sectNode.AppendChild(newXmlNode); XmlNode lastNode = FindNodeByValue(sectNode.ChildNodes, currentTagToReplace.TagsNode.OuterXml); XmlNode nodeToReplace = FindAfterParentNode(sectNode, lastNode); if (nodeToReplace != null) { sectNode.ReplaceChild(newXmlNode, nodeToReplace); } } else { XmlNode childNode = FindNodeByValue(document.ChildNodes, currentTagToReplace.TagsNode.Value); childNode.Value = "Данные не внесены"; } } else if (currentTagToReplace.ReplaceType == 1) { XmlNode childNode = FindNodeByValue(document.ChildNodes, "ZLinez" + currentTagToReplace.ReplacemantList[0] + "Z"); zColumnTable currentColumn = FindColumnWithUniqueMark(applicationId, currentTagToReplace.ReplacemantList[0]); if (currentColumn != null) { childNode.Value = FindValue(currentColumn, applicationId); } if (childNode == null) { //childNode.Value = "Значение отсутствует"; } } } #endregion #region подчищаем и сохраняем в файл string newXmlFile = document.OuterXml; newXmlFile = newXmlFile.Replace("xmlns:w=\"w\"", "").Replace("xmlns:wx=\"wx\"", "").Replace("xmlns:wsp=\"wsp\"", ""); File.WriteAllText(newFilePath, newXmlFile); #endregion #region конвертируем его в другой формат Converter converter = new Converter(); converter.Convert(newFilePath, newFilePath, documentType); ConvertedFileExtension = converter.ConvertedFilaExtension; ConvertedFilePath = converter.ConvertedFilePath; #endregion return(true); }