//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< private static string XmlDeletionContent(string xml) { var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); var nodes = xmlDoc.GetElementsByTagName("CBC_OECD"); StringBuilder sbResults = new StringBuilder(); foreach (XmlNode node in nodes) { var CbcBodies = node.SelectNodes("CbcBody"); var messageSpec = node.SelectSingleNode("MessageSpec"); var corrMessageRefId = GetMessageRefId(messageSpec); if (CbcBodies != null) { foreach (XmlNode CbcBody in CbcBodies) { var reportingEntity = CbcBody.SelectSingleNode("ReportingEntity"); var reports = CbcBody.SelectNodes("CbcReports"); var additionalInfo = CbcBody.SelectNodes("AdditionalInfo"); if (reportingEntity != null) { //reporting entity if (reportingEntity != null) { var reportingEntityXml = CheckEntity(reportingEntity, corrMessageRefId, xmlDoc); if (!string.IsNullOrEmpty(reportingEntityXml.ToString())) { sbResults.Append(reportingEntityXml.ToString()); } } } //if there is 1 or more cbcReports if (reports != null) { var reportsXml = CheckContainerForDeletion(reports, corrMessageRefId, xmlDoc); if (!string.IsNullOrEmpty(reportsXml.ToString())) { sbResults.Append(reportsXml.ToString()); } } //if there is 1 or more additionalInfo if (additionalInfo != null) { var additionalInfoXml = CheckContainerForDeletion(additionalInfo, corrMessageRefId, xmlDoc); if (!string.IsNullOrEmpty(additionalInfoXml.ToString())) { sbResults.Append(additionalInfoXml.ToString()); } } } } } return(sbResults.ToString()); }
private static string XmlDeletionContent(decimal id, string corrMessageRefId, string xml, string reportingPeriod) { var xmlDoc = Common.CreateNewDocument(); xmlDoc.LoadXml(xml); var cbcDocument = Common.CreateNewDocument(); var cbcBody = cbcDocument.CreateNode(XmlNodeType.Element, "CbcBody", null); var CbcBodies = xmlDoc.SelectNodes("CbcBody"); if (CbcBodies != null) { foreach (XmlNode CbcBody in CbcBodies) { var reportingEntity = CbcBody.SelectSingleNode("ReportingEntity"); var reports = CbcBody.SelectNodes("CbcReports"); var additionalInfo = CbcBody.SelectNodes("AdditionalInfo"); if (reportingEntity != null) { //reporting entity var newreportingEntity = cbcDocument.CreateNode(XmlNodeType.Element, "ReportingEntity", null); var reportingEntityXml = CheckEntity(id, reportingEntity, corrMessageRefId); if (!string.IsNullOrEmpty(reportingEntityXml.ToString())) { newreportingEntity.InnerXml = reportingEntityXml.InnerXml; cbcBody.AppendChild(newreportingEntity); } } //if there is 1 or more cbcReports if (reports != null) { var newReport = cbcDocument.CreateNode(XmlNodeType.Element, "CbcReports", null); var reportsXml = CheckContainerForDeletion(id, reports, corrMessageRefId, xmlDoc); if (!string.IsNullOrEmpty(reportsXml.ToString())) { GetReportsAndAdditionalInfo(BuildXml(reportsXml.ToString()), ref cbcBody); } } //if there is 1 or more additionalInfo if (additionalInfo != null) { var newAdditionalInfo = cbcDocument.CreateNode(XmlNodeType.Element, "AdditionalInfo", null); var additionalInfoXml = CheckContainerForDeletion(id, additionalInfo, corrMessageRefId, xmlDoc); if (!string.IsNullOrEmpty(additionalInfoXml.ToString())) { GetReportsAndAdditionalInfo(BuildXml(additionalInfoXml.ToString()), ref cbcBody); } } } } return(cbcBody.InnerXml); }
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #region xmlWithNameSpace private static string XmlNMDeletionContent(decimal id, string corrMessageRefId, string xml, string reportingPeriod) { var xmlDoc = Common.CreateNewDocument(); xmlDoc.LoadXml(xml); XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable); nsmgr.AddNamespace("urn", "urn:oecd:ties:cbc:v1"); nsmgr.AddNamespace("stf", "urn:oecd:ties:stf:v4"); var cbcDocument = Common.CreateNewDocument(); var cbcBody = cbcDocument.CreateNode(XmlNodeType.Element, "CbcBody", cbcDocument.NamespaceURI); //var CbcBodies = xmlDoc.SelectNodes("urn:CbcBody", nsmgr); var CbcBodies = xmlDoc.SelectNodes("CbcBody"); if (CbcBodies.Count == 0) { CbcBodies = xmlDoc.SelectNodes("urn:CbcBody", nsmgr); } if (CbcBodies != null) { foreach (XmlNode CbcBody in CbcBodies) { var reportingEntity = CbcBody.SelectSingleNode("urn:ReportingEntity", nsmgr); var reports = CbcBody.SelectNodes("urn:CbcReports", nsmgr); var additionalInfo = CbcBody.SelectNodes("urn:AdditionalInfo", nsmgr); if (reportingEntity != null) { //reporting entity var newreportingEntity = cbcDocument.CreateNode(XmlNodeType.Element, "ReportingEntity", "urn:oecd:ties:cbc:v1"); var reportingEntityXml = CheckNMEntity(id, reportingEntity, corrMessageRefId, nsmgr); if (!string.IsNullOrEmpty(reportingEntityXml.ToString())) { newreportingEntity.InnerXml = reportingEntityXml.InnerXml; cbcBody.AppendChild(newreportingEntity); } } //if there is 1 or more cbcReports if (reports != null) { var newReport = cbcDocument.CreateNode(XmlNodeType.Element, "CbcReports", "urn:oecd:ties:cbc:v1"); var reportsXml = CheckNMContainerForDeletion(id, reports, corrMessageRefId, xmlDoc, nsmgr); if (!string.IsNullOrEmpty(reportsXml.ToString())) { GetReportsAndAdditionalInfo(BuildXml(reportsXml.ToString()), ref cbcBody); } } //if there is 1 or more additionalInfo if (additionalInfo != null) { var newAdditionalInfo = cbcDocument.CreateNode(XmlNodeType.Element, "AdditionalInfo", "urn:oecd:ties:cbc:v1"); var additionalInfoXml = CheckNMContainerForDeletion(id, additionalInfo, corrMessageRefId, xmlDoc, nsmgr); if (!string.IsNullOrEmpty(additionalInfoXml.ToString())) { GetReportsAndAdditionalInfo(BuildXml(additionalInfoXml.ToString()), ref cbcBody); } } } } return(cbcBody.InnerXml); }