NFe.Components.XMLIniFile.WriteThisValue C# (CSharp) Method

WriteThisValue() protected method

protected WriteThisValue ( string Path, string ValueSection, string Value ) : void
Path string
ValueSection string
Value string
return void
        protected void WriteThisValue(string Path, string ValueSection, string Value)
		{
			try
			{
				XmlNode node = GetPathNode(Path, true);
				if (node!=null)
				{
					if (node.Attributes.GetNamedItem( ValueSection )!=null)
					{
						node = node.Attributes.GetNamedItem( ValueSection );
						node.Value = Value;
					}
					else
					{
						XmlNode xmlInf;
						XmlAttribute xmlSection;

						switch(aXmlFormat)
						{
							case Store.SameElement:
							{
								//
								// cria um elemento no mesmo path+item
								// 
								xmlSection = xmldoc.CreateAttribute(ValueSection);
								xmlSection.Value = Value;
								node.Attributes.Append(xmlSection);
								break;
							}

							case Store.MultiElements:
							{
								//
								// cria um elemento no path com niveis
								// 
								for(int i=0; i<node.ChildNodes.Count; ++i)
									if (node.ChildNodes[i].LocalName==ValueSection)
									{
										node.ChildNodes[i].InnerText = Value;
										return;
									}
								xmlInf = xmldoc.CreateElement("", ValueSection, "");
                                if (!string.IsNullOrEmpty(Value))
								    xmlInf.InnerText = Value;
								node.AppendChild(xmlInf);
								break;
							}
						}
					}
                    Modified = true;
                }
			}
			catch (Exception ex)
			{
				throw new Exception(ex.Message+"\n\r"+String.Format("Não pode salvar '{0} - {1} = {2}'", Path, ValueSection, Value));
			}
		}