FromXml Method
Collapse the table of content
Expand the table of content

DnsPermission.FromXml Method

Reconstructs a DnsPermission instance from an XML encoding.

Namespace:  System.Net
Assembly:  System (in System.dll)

public override function FromXml(
	securityElement : SecurityElement
)

Parameters

securityElement
Type: System.Security.SecurityElement

The XML encoding to use to reconstruct the DnsPermission instance.

Implements

ISecurityEncodable.FromXml(SecurityElement)

ExceptionCondition
ArgumentNullException

securityElement is a null reference (Nothing in Visual Basic).

ArgumentException

securityElement is not a DnsPermission element.

The FromXml method reconstructs a DnsPermission instance from an XML encoding defined by the SecurityElement class.

Use the ToXml method to XML-encode the DnsPermission instance, including state information.

The following example reconstructs a DnsPermission instance from an XML encoding.

No code example is currently available or this language may not be supported.
public:
   void ConstructDnsPermission()
   {
      try
      {
         // Create a DnsPermission instance.
         DnsPermission* permission = new DnsPermission(PermissionState::None);
         // Create a SecurityElement instance by calling the ToXml method on the
         // DnsPermission instance.
         // Print its attributes, which hold the  XML encoding of the DnsPermission
         // instance.
         Console::WriteLine(S"Attributes and Values of 'DnsPermission' instance :");
         PrintKeysAndValues(permission->ToXml()->Attributes);

         // Create a SecurityElement instance.
         SecurityElement* securityElementObj = new SecurityElement(S"IPermission");
         // Add attributes and values of the SecurityElement instance corresponding to
         // the permission instance.
         securityElementObj->AddAttribute(S"version", S"1");
         securityElementObj->AddAttribute(S"Unrestricted", S"true");
         securityElementObj->AddAttribute(S"class", S"System.Net.DnsPermission");

         // Reconstruct a DnsPermission instance from an XML encoding.
         DnsPermission* permission1 = new DnsPermission(PermissionState::None);
         permission1->FromXml(securityElementObj);

         // Print the attributes and values of the constructed DnsPermission Object*.
         Console::WriteLine(S"After reconstruction Attributes and Values of new DnsPermission instance :");
         PrintKeysAndValues(permission1->ToXml()->Attributes);
      }
      catch (NullReferenceException* e)
      {
         Console::WriteLine(S"NullReferenceException caught!!!");
         Console::WriteLine(S"Source : {0}", e->Source);
         Console::WriteLine(S"Message : {0}", e->Message);
      }
      catch (SecurityException* e)
      {
         Console::WriteLine(S"SecurityException caught!!!");
         Console::WriteLine(S"Source : {0}", e->Source);
         Console::WriteLine(S"Message : {0}", e->Message);
      }
      catch (ArgumentNullException* e)
      {
         Console::WriteLine(S"ArgumentNullException caught!!!");
         Console::WriteLine(S"Source : {0}", e->Source);
         Console::WriteLine(S"Message : {0}", e->Message);
      }
      catch (Exception* e)
      {
         Console::WriteLine(S"Exception caught!!!");
         Console::WriteLine(S"Source : {0}", e->Source);
         Console::WriteLine(S"Message : {0}", e->Message);
      }
   }

private:
   void PrintKeysAndValues(Hashtable * myList)
   {
      // Get the enumerator that can iterate through the hash table.
      IDictionaryEnumerator* myEnumerator = myList->GetEnumerator();
      Console::WriteLine(S"\t-KEY-\t-VALUE-");
      while (myEnumerator->MoveNext())
         Console::WriteLine(S"\t {0}:\t {1}", 
         myEnumerator->Key, myEnumerator->Value);
      Console::WriteLine();
   }

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2016 Microsoft