ISecurityEncodable::FromXml Method (SecurityElement^)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Reconstructs a security object with a specified state from an XML encoding.

Namespace:   System.Security
Assembly:  mscorlib (in mscorlib.dll)

void FromXml(
	SecurityElement^ e


Type: System.Security::SecurityElement^

The XML encoding to use to reconstruct the security object.

Custom code that extends security objects needs to implement the ToXml and FromXml methods to make the objects security-encodable.

The following code example demonstrates implementing the FromXml method. This code example is part of a larger example provided for the ISecurityEncodable class.

    // Populate the permission's fields from XML.
    virtual void FromXml(SecurityElement^ element) override
        specifiedAsUnrestricted = false;
        stateFlags = (SoundPermissionState)0;

        // If XML indicates an unrestricted permission, 
        // make this permission unrestricted.
        String^ attributeString = 
            (String^) element->Attributes["Unrestricted"];
        if (attributeString != nullptr)
            specifiedAsUnrestricted = Convert::ToBoolean(attributeString);
            if (specifiedAsUnrestricted)
                stateFlags = SoundPermissionState::PlayAnySound;

        // If XML indicates a restricted permission, parse the flags.
        if (!specifiedAsUnrestricted)
            attributeString = (String^) element->Attributes["Flags"];
            if (attributeString != nullptr)
                stateFlags = (SoundPermissionState) Convert::ToInt32(
                    attributeString, true));

.NET Framework
Available since 1.1
Return to top