// Build the PhoneMetadataCollection from the input XML file.
public static PhoneMetadataCollection BuildPhoneMetadataCollection(string name,
bool liteBuild, bool specialBuild, bool isShortNumberMetadata,
bool isAlternateFormatsMetadata)
{
XDocument document;
#if (NET35 || NET40)
var asm = Assembly.GetExecutingAssembly();
#else
var asm = typeof(PhoneNumberUtil).GetTypeInfo().Assembly;
#endif
using (var input = asm.GetManifestResourceStream(name))
{
#if NET35
document = XDocument.Load(new XmlTextReader(input));
#else
document = XDocument.Load(input);
#endif
}
var metadataCollection = new PhoneMetadataCollection.Builder();
var metadataFilter = GetMetadataFilter(liteBuild, specialBuild);
foreach (var territory in document.GetElementsByTagName("territory"))
{
// For the main metadata file this should always be set, but for other supplementary data
// files the country calling code may be all that is needed.
var regionCode = territory.GetAttribute("id");
var metadata = LoadCountryMetadata(regionCode, territory,
isShortNumberMetadata, isAlternateFormatsMetadata);
metadataFilter.FilterMetadata(metadata);
metadataCollection.AddMetadata(metadata);
}
return(metadataCollection.Build());
}