This documentation is archived and is not being maintained.

DnsPermission.FromXml Method

Reconstructs a DnsPermission instance from an XML encoding.

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

'Declaration
Public Overrides Sub FromXml ( _
	securityElement As 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 Nothing.

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.


    Public Sub ConstructDnsPermission()
        Try
            ' Create a DnsPermission instance.
            Dim permission As New DnsPermission(PermissionState.None)
            ' Create a SecurityElement instance by calling the ToXml method on the
            ' DnsPermission instance and print its attributes, 
            ' which hold the  XML encoding of the DnsPermission instance.
            Console.WriteLine("Attributes and Values of 'DnsPermission' instance :")
            PrintKeysAndValues(permission.ToXml().Attributes)

            ' Create a SecurityElement instacnce .
            Dim securityElementObj As New SecurityElement("IPermission")
            ' Add attributes and values of the SecurityElement instance corresponding to
            ' teh permission instance.
            securityElementObj.AddAttribute("version", "1")
            securityElementObj.AddAttribute("Unrestricted", "true")
            securityElementObj.AddAttribute("class", "System.Net.DnsPermission")

            ' Reconstruct a DnsPermission instance from an XML encoding.
            Dim permission1 As New DnsPermission(PermissionState.None)
            permission1.FromXml(securityElementObj)

            ' Print the attributes and values of the constructed DnsPermission object.
            Console.WriteLine("After reconstruction Attributes and Values of new DnsPermission instance :")
            PrintKeysAndValues(permission1.ToXml().Attributes)
        Catch e As NullReferenceException
            Console.WriteLine("NullReferenceException caught!!!")
            Console.WriteLine(("Source : " + e.Source))
            Console.WriteLine(("Message : " + e.Message))
        Catch e As SecurityException
            Console.WriteLine("SecurityException caught!!!")
            Console.WriteLine(("Source : " + e.Source))
            Console.WriteLine(("Message : " + e.Message))
        Catch e As ArgumentNullException
            Console.WriteLine("ArgumentNullException caught!!!")
            Console.WriteLine(("Source : " + e.Source))
            Console.WriteLine(("Message : " + e.Message))
        Catch e As Exception
            Console.WriteLine("Exception caught!!!")
            Console.WriteLine(("Source : " + e.Source))
            Console.WriteLine(("Message : " + e.Message))
        End Try
    End Sub 'ConstructDnsPermission


    Private Sub PrintKeysAndValues(myList As Hashtable)
        ' Get the enumerator that can iterate through the hash table.
        Dim myEnumerator As IDictionaryEnumerator = myList.GetEnumerator()
        Console.WriteLine(ControlChars.Tab + "-KEY-" + ControlChars.Tab + "-VALUE-")
        While myEnumerator.MoveNext()
            Console.WriteLine(ControlChars.Tab + "{0}:" + ControlChars.Tab + "{1}", myEnumerator.Key, myEnumerator.Value)
        End While
        Console.WriteLine()
    End Sub 'PrintKeysAndValues



.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: