Compartir a través de


AsymmetricAlgorithm.FromXmlString(String) Método

Definición

Cuando se invalida en una clase derivada, reconstruye un objeto AsymmetricAlgorithm a partir de una cadena XML. En caso contrario, produce una excepción NotImplementedException.

public:
 virtual void FromXmlString(System::String ^ xmlString);
public:
 abstract void FromXmlString(System::String ^ xmlString);
public virtual void FromXmlString (string xmlString);
public abstract void FromXmlString (string xmlString);
abstract member FromXmlString : string -> unit
override this.FromXmlString : string -> unit
abstract member FromXmlString : string -> unit
Public Overridable Sub FromXmlString (xmlString As String)
Public MustOverride Sub FromXmlString (xmlString As String)

Parámetros

xmlString
String

Cadena XML que se usa para reconstruir el objeto AsymmetricAlgorithm.

Ejemplos

En el ejemplo de código siguiente se muestra cómo implementar el FromXmlString método para analizar la cadena XML especificada para rellenar el objeto actual CspParameters . Este ejemplo de código es parte de un ejemplo más grande proporcionado para la clase AsymmetricAlgorithm.

    // Expected XML schema:
    //      <ProviderName></ProviderName>
    //      <KeyContainerName></KeyContainerName>
    //      <KeyNumber></KeyNumber>
    //      <ProviderType></ProviderType>
public:
    virtual void FromXmlString(String^ xmlString) override 
    {
        if (xmlString != nullptr)
        {
            XmlDocument^ document = gcnew XmlDocument();
            document->LoadXml(xmlString);
            XmlNode^ firstNode = document->FirstChild;
            XmlNodeList^ nodeList;

            // Assemble parameters from values in each XML element.
            cryptoServiceParameters = gcnew CspParameters();

            // KeyContainerName is optional.
            nodeList = 
                document->GetElementsByTagName("KeyContainerName");
            if (nodeList->Count > 0)
            {
                cryptoServiceParameters->KeyContainerName =
                    nodeList->Item(0)->InnerText;
            }

            // KeyNumber is optional.
            nodeList = document->GetElementsByTagName("KeyNumber");
            if (nodeList->Count > 0)
            {
                cryptoServiceParameters->KeyNumber =
                    Int32::Parse(nodeList->Item(0)->InnerText);
            }

            // ProviderName is optional.
            nodeList = document->GetElementsByTagName("ProviderName");
            if (nodeList->Count > 0)
            {
                cryptoServiceParameters->ProviderName =
                    nodeList->Item(0)->InnerText;
            }

            // ProviderType is optional.
            nodeList = document->GetElementsByTagName("ProviderType");
            if (nodeList->Count > 0)
            {
                cryptoServiceParameters->ProviderType =
                    Int32::Parse(nodeList->Item(0)->InnerText);
            }
        }
        else
        {
            throw gcnew ArgumentNullException("xmlString");
        }
    }
// Expected XML schema:
//      <ProviderName></ProviderName>
//      <KeyContainerName></KeyContainerName>
//      <KeyNumber></KeyNumber>
//      <ProviderType></ProviderType>
public override void FromXmlString(string xmlString)
{
    if (xmlString != null)
    {
        XmlDocument doc = new XmlDocument();
        doc.LoadXml(xmlString);
        XmlNode firstNode = doc.FirstChild;
        XmlNodeList nodeList;

        // Assemble parameters from values in each XML element.
        cspParameters = new CspParameters();

        // KeyContainerName is optional.
        nodeList = doc.GetElementsByTagName("KeyContainerName");
        string keyName = nodeList.Item(0).InnerText;
        if (keyName != null) 
        {
            cspParameters.KeyContainerName = keyName;
        }

        // KeyNumber is optional.
        nodeList = doc.GetElementsByTagName("KeyNumber");
        string keyNumber = nodeList.Item(0).InnerText;
        if (keyNumber != null) 
        {
            cspParameters.KeyNumber = Int32.Parse(keyNumber);
        }

        // ProviderName is optional.
        nodeList = doc.GetElementsByTagName("ProviderName");
        string providerName = nodeList.Item(0).InnerText;
        if (providerName != null) 
        {
            cspParameters.ProviderName = providerName;
        }

        // ProviderType is optional.
        nodeList = doc.GetElementsByTagName("ProviderType");
        string providerType = nodeList.Item(0).InnerText;
        if (providerType != null) 
        {
            cspParameters.ProviderType = Int32.Parse(providerType);
        }
    }
    else
    {
        throw new ArgumentNullException("xmlString");
    }
}
' Expected XML schema:
'      <ProviderName></ProviderName>
'      <KeyContainerName></KeyContainerName>
'      <KeyNumber></KeyNumber>
'      <ProviderType></ProviderType>
Public Overrides Sub FromXmlString(ByVal xmlString As String)
    If Not xmlString Is Nothing Then
        Dim doc As New XmlDocument
        doc.LoadXml(xmlString)
        Dim firstNode As XmlNode = doc.FirstChild
        Dim nodeList As XmlNodeList

        ' Assemble parameters from values in each XML element.
        cspParameters = New CspParameters

        ' KeyContainerName is optional.
        nodeList = doc.GetElementsByTagName("KeyContainerName")
        Dim keyName As String = nodeList.Item(0).InnerText
        If Not keyName Is Nothing Then
            cspParameters.KeyContainerName = keyName
        End If

        ' KeyNumber is optional.
        nodeList = doc.GetElementsByTagName("KeyNumber")
        Dim keyNumber As String = nodeList.Item(0).InnerText
        If Not keyNumber Is Nothing Then
            cspParameters.KeyNumber = Int32.Parse(keyNumber)
        End If

        ' ProviderName is optional.
        nodeList = doc.GetElementsByTagName("ProviderName")
        Dim providerName As String = nodeList.Item(0).InnerText
        If Not providerName Is Nothing Then
            cspParameters.ProviderName = providerName
        End If

        ' ProviderType is optional.
        nodeList = doc.GetElementsByTagName("ProviderType")
        Dim providerType As String = nodeList.Item(0).InnerText
        If Not providerType Is Nothing Then
            cspParameters.ProviderType = Int32.Parse(providerType)
        End If
    Else
        Throw New ArgumentNullException("xmlString")
    End If
End Sub

Se aplica a

Consulte también