Export (0) Print
Expand All

CultureAndRegionInfoBuilder.CreateFromLdml Method

Reconstitutes a CultureAndRegionInfoBuilder object from a specified XML file that contains a representation of the object.

Namespace:  System.Globalization
Assembly:  sysglobl (in sysglobl.dll)

public static CultureAndRegionInfoBuilder CreateFromLdml(
	string xmlFileName
)

Parameters

xmlFileName
Type: System.String

A file name that contains the XML representation of a CultureAndRegionInfoBuilder object.

Return Value

Type: System.Globalization.CultureAndRegionInfoBuilder
A new object that is equivalent to the information stored in the xmlFileName parameter.

ExceptionCondition
ArgumentNullException

xmlFileName is null.

ArgumentException

xmlFileName is an empty string (""), or invalid file or path name.

XmlException

The data in xmlFileName is not in valid XML format.

-or-

An I/O error occurred while accessing xmlFileName.

XmlSchemaValidationException

The data in xmlFileName is not in valid LDML format.

The xmlFileName parameter specifies a file name that contains the XML representation of a CultureAndRegionInfoBuilder object. The format of the XML file is called Locale Data Markup Language (LDML) version 1.1. A new CultureAndRegionInfoBuilder object is created and initialized with the data in xmlFileName. The Save method performs the reverse operation of the CreateFromLdml method.

In the LDML file, the properties of a culture are specified as child elements of the <special> element in the <identity> section. A property value is typically specified by the element's type attribute. 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>

For more information about the LDML standard, see Unicode Technical Standard #35, "Locale Data Markup Language (LDML)" on the Unicode Consortium website.

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".

*/

.NET Framework

Supported in: 4.6, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft