CultureAndRegionInfoBuilder.CreateFromLdml(String) Méthode

Définition

Reconstitue un objet CultureAndRegionInfoBuilder d'un fichier XML spécifié qui contient une représentation de l'objet.Reconstitutes a CultureAndRegionInfoBuilder object from a specified XML file that contains a representation of the object.

public:
 static System::Globalization::CultureAndRegionInfoBuilder ^ CreateFromLdml(System::String ^ xmlFileName);
public static System.Globalization.CultureAndRegionInfoBuilder CreateFromLdml (string xmlFileName);
static member CreateFromLdml : string -> System.Globalization.CultureAndRegionInfoBuilder
Public Shared Function CreateFromLdml (xmlFileName As String) As CultureAndRegionInfoBuilder

Paramètres

xmlFileName
String

Nom de fichier qui contient la représentation XML d'un objet CultureAndRegionInfoBuilder.A file name that contains the XML representation of a CultureAndRegionInfoBuilder object.

Retours

CultureAndRegionInfoBuilder

Nouvel objet qui est équivalent aux informations stockées dans le paramètre xmlFileName.A new object that is equivalent to the information stored in the xmlFileName parameter.

Exceptions

xmlFileName a la valeur null.xmlFileName is null.

xmlFileName est une chaîne vide (""), ou un nom de fichier ou de chemin d’accès non valide.xmlFileName is an empty string (""), or invalid file or path name.

Les données dans xmlFileName ne sont pas au format XML valide.The data in xmlFileName is not in valid XML format.

-ou--or- Une erreur d’E/S s’est produite au moment de l’accès à xmlFileName.An I/O error occurred while accessing xmlFileName.

Les données dans xmlFileName ne sont pas au format LDML valide.The data in xmlFileName is not in valid LDML format.

Exemples

L’exemple suivant illustre les méthodes Save et CreateFromLdml.The following example demonstrates the Save and CreateFromLdml methods.

// This example demonstrates the CultureAndRegionInfoBuilder.Save and
// CreateFromLdml methods.
// Compile this example with a reference to sysglobl.dll.

using System;
using System.Globalization;
using System.IO;
using System.Xml;

class Sample
{
    public static void Main()
    {
    string savedCARIB = "mySavedCARIB.xml";
    string msg1 = "The name of the original CultureAndRegionInfoBuilder" +
                  " is \"{0}\".";
    string msg2 = "Reconstituting the CultureAndRegionInfoBuilder object " +
                  "from \"{0}\".";
    string msg3 = "The name of the reconstituted CultureAndRegionInfoBuilder" +
                  " is \"{0}\".";

// Construct a new, privately used culture that extends the en-US culture
// provided by the .NET Framework. In this sample, the CultureAndRegion-
// Types.Specific parameter creates a minimal CultureAndRegionInfoBuilder
// object that you must populate with culture and region information.

    CultureAndRegionInfoBuilder cib1 = null;
    CultureAndRegionInfoBuilder cib2 = null;
    try {
        cib1 = new CultureAndRegionInfoBuilder(
                           "x-en-US-sample", CultureAndRegionModifiers.None);
        }
    catch (ArgumentException ae)
        {
        Console.WriteLine(ae);
        return;
        }

// Populate the new CultureAndRegionInfoBuilder object with culture information.
    CultureInfo ci = new CultureInfo("en-US");
    cib1.LoadDataFromCultureInfo(ci);

// Populate the new CultureAndRegionInfoBuilder object with region information.
    RegionInfo  ri = new RegionInfo("US");
    cib1.LoadDataFromRegionInfo(ri);

// Display a property of the new custom culture.
    Console.Clear();
    Console.WriteLine(msg1, cib1.CultureName);

// Save the new CultureAndRegionInfoBuilder object in the specified file in
// LDML format. The file is saved in the same directory as the application
// that calls the Save method.

    Console.WriteLine("Saving the custom culture to a file...");
    try {
        cib1.Save( savedCARIB );
        }
    catch (IOException exc)
        {
        Console.WriteLine("** I/O exception: {0}", exc.Message);
        return;
        }

// Create a new CultureAndRegionInfoBuilder object from the persisted file.
    Console.WriteLine(msg2, savedCARIB);
    try {
        cib2 = CultureAndRegionInfoBuilder.CreateFromLdml( savedCARIB );
        }
    catch (XmlException xe)
        {
        Console.WriteLine("** XML validation exception: {0}", xe.Message);
        return;
        }

// Display a property of the resonstituted custom culture.
    Console.WriteLine(msg3, cib2.CultureName);

// At this point you could call the Register method and make the reconstituted
// custom culture available to other applications. The mySavedCARIB.xml file
// remains on your computer.
    }
}

/*
This code example produces the following results:

The name of the original CultureAndRegionInfoBuilder is "x-en-US-sample".
Saving the custom culture to a file...
Reconstituting the CultureAndRegionInfoBuilder object from "mySavedCARIB.xml".
The name of the reconstituted CultureAndRegionInfoBuilder is "x-en-US-sample".

*/
' This example demonstrates the CultureAndRegionInfoBuilder.Save and 
' CreateFromLdml methods.
' Compile this example with a reference to sysglobl.dll.

Imports System.Globalization
Imports System.IO
Imports System.Xml

Class Sample
    Public Shared Sub Main() 
        Dim savedCARIB As String = "mySavedCARIB.xml"
        Dim msg1 As String = "The name of the original CultureAndRegionInfoBuilder" & _
                             " is ""{0}""."
        Dim msg2 As String = "Reconstituting the CultureAndRegionInfoBuilder object " & _
                             "from ""{0}""."
        Dim msg3 As String = "The name of the reconstituted CultureAndRegionInfoBuilder" & _
                             " is ""{0}""."

        ' Construct a new, privately used culture that extends the en-US culture 
        ' provided by the .NET Framework. In this sample, the CultureAndRegion-
        ' Types.Specific parameter creates a minimal CultureAndRegionInfoBuilder 
        ' object that you must populate with culture and region information.

        Dim cib1 As CultureAndRegionInfoBuilder = Nothing
        Dim cib2 As CultureAndRegionInfoBuilder = Nothing
        
        Try
            cib1 = New CultureAndRegionInfoBuilder("x-en-US-sample", _
                                        CultureAndRegionModifiers.None)
        Catch ae As ArgumentException
            Console.WriteLine(ae)
            Return
        End Try
        
        ' Populate the new CultureAndRegionInfoBuilder object with culture information.
        Dim ci As New CultureInfo("en-US")
        cib1.LoadDataFromCultureInfo(ci)
        
        ' Populate the new CultureAndRegionInfoBuilder object with region information.
        Dim ri As New RegionInfo("US")
        cib1.LoadDataFromRegionInfo(ri)
        
        ' Display a property of the new custom culture.
        Console.Clear()
        Console.WriteLine(msg1, cib1.CultureName)
        
        ' Save the new CultureAndRegionInfoBuilder object in the specified file in
        ' LDML format. The file is saved in the same directory as the application 
        ' that calls the Save method.

        Console.WriteLine("Saving the custom culture to a file...")
        Try
            cib1.Save(savedCARIB)
        Catch exc As IOException
            Console.WriteLine("** I/O exception: {0}", exc.Message)
            Return
        End Try
        
        ' Create a new CultureAndRegionInfoBuilder object from the persisted file.
        Console.WriteLine(msg2, savedCARIB)
        Try
            cib2 = CultureAndRegionInfoBuilder.CreateFromLdml(savedCARIB)
        Catch xe As XmlException
            Console.WriteLine("** XML validation exception: {0}", xe.Message)
            Return
        End Try
        
        ' Display a property of the resonstituted custom culture.
        Console.WriteLine(msg3, cib2.CultureName)

        ' At this point you could call the Register method and make the reconstituted
        ' custom culture available to other applications. The mySavedCARIB.xml file
        ' remains on your computer.

    End Sub
End Class

'This code example produces the following results:
'
'The name of the original CultureAndRegionInfoBuilder is "x-en-US-sample".
'Saving the custom culture to a file...
'Reconstituting the CultureAndRegionInfoBuilder object from "mySavedCARIB.xml".
'The name of the reconstituted CultureAndRegionInfoBuilder is "x-en-US-sample".
'

Remarques

Le paramètre xmlFileName spécifie un nom de fichier qui contient la représentation XML d’un objet CultureAndRegionInfoBuilder.The xmlFileName parameter specifies a file name that contains the XML representation of a CultureAndRegionInfoBuilder object. Le format du fichier XML est appelé paramètres LDML (locale Data Markup Language) version 1,1.The format of the XML file is called Locale Data Markup Language (LDML) version 1.1. Un nouvel objet CultureAndRegionInfoBuilder est créé et initialisé avec les données de xmlFileName.A new CultureAndRegionInfoBuilder object is created and initialized with the data in xmlFileName. La méthode Save effectue l’opération inverse de la méthode CreateFromLdml.The Save method performs the reverse operation of the CreateFromLdml method.

Dans le fichier LDML, les propriétés d’une culture sont spécifiées en tant qu’éléments enfants de l’élément <special> dans la section <identity>.In the LDML file, the properties of a culture are specified as child elements of the <special> element in the <identity> section. Une valeur de propriété est généralement spécifiée par l’attribut type de l’élément.A property value is typically specified by the element's type attribute. Par exemple, l’extrait suivant d’un fichier LDML définit le parent d’une culture comme culture neutre en anglais.For example, the following excerpt from an LDML file defines a culture's parent as the English neutral culture.

<identity>  
   <version number="1.1">ldml version 1.1</version>  
   <generation date="2012-05-16" />  
   <special xmlns:msLocale="http://schemas.microsoft.com/globalization/2004/08/carib/ldml">  
      <!-content removed -->  
      <msLocale:parentName type="en" />  
      <!-content removed -->  
   </special>  
</identity>  

Pour plus d’informations sur la norme LDML, consultez Unicode Technical standard #35, « locale Data Markup Language (LDML) » sur le site Web du consortium Unicode.For more information about the LDML standard, see Unicode Technical Standard #35, "Locale Data Markup Language (LDML)" on the Unicode Consortium website.

S’applique à

Voir aussi