//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// UserRTX.NET satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.Xml;

#if !WASM
namespace user_rtx { using u = user_rtx;
#else
namespace user_rtx.wasm { using u = user_rtx.wasm;
#endif

partial class XmlConfigurationBase {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/// <exception cref="InvalidOperationException" />
/// <exception cref="EXmlConfiguration" />
protected XmlElement CreateElement( string name )
{
   VerifyDocumentLoaded();
   try {
      return Document.CreateElement( name, TargetNamespace ); }
   catch ( Exception e ) {
      throw CreateExceptionWithFile( e.Message ); }
}

//--------------------------------------------------------------------------------------------------

/// <exception cref="InvalidOperationException" />
/// <exception cref="EXmlConfiguration" />
protected XmlElement CreateAndAppendElement( string name )
{
   var element = CreateElement( name );
   CurrentElement.AppendChild( element );
   return element;
}

//==================================================================================================

/// <exception cref="InvalidOperationException" />
/// <exception cref="ENotFound" />
/// <exception cref="EXmlConfiguration" />
protected void RemoveAttribute( string name ) =>
   RemoveAttribute( name, false );

/// <exception cref="InvalidOperationException" />
/// <exception cref="ENotFound" />
/// <exception cref="EXmlConfiguration" />
bool RemoveAttribute( string name, bool ignoreNotFoundError )
{
   VerifyCurrentElementSelected();
   try {
      var attribute = CurrentElement.GetAttributeNode( name );
      if ( attribute == null )
         if ( ignoreNotFoundError )
            return false;
         else
            throw new ENotFound(ProvideErrorMessageWithFile(u.local.T(
               RC._Attribute_not_found_0,
               "Атрибут не найден: “{0}”." ),
               name ));
      CurrentElement.RemoveAttributeNode( attribute );
   }
   catch ( Exception e ) {
      var configurationException = CreateExceptionWithPath( e.Message );
      if ( e is ENotFound )
         throw new ENotFound( configurationException.Message );
      throw configurationException;
   }
   return true;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // XmlConfigurationBase

} // user_rtx (.wasm)
