Share via


AsymmetricAlgorithm.FromXmlString(String) メソッド

定義

派生クラスでオーバーライドされた場合は、XML 文字列から AsymmetricAlgorithm オブジェクトを再構築します。 それ以外の場合は、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)

パラメーター

xmlString
String

AsymmetricAlgorithm オブジェクトの再構築に使用する XML 文字列。

次のコード例では、 メソッドを実装 FromXmlString して、指定した XML 文字列を解析して現在 CspParameters のオブジェクトにデータを設定する方法を示します。 このコード例は、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

適用対象

こちらもご覧ください