private void Load()

in src/lib/Microsoft.Fx.Portability/TargetMapper.cs [89:153]


        private void Load(Stream stream, string path)
        {
            var readerSettings = new XmlReaderSettings
            {
                CheckCharacters = true,
                CloseInput = false,
                IgnoreComments = true,
                IgnoreWhitespace = true,
                DtdProcessing = DtdProcessing.Prohibit,
                XmlResolver = null
            };

            try
            {
                using (var xmlReader = XmlReader.Create(stream, readerSettings))
                {
                    var doc = XDocument.Load(xmlReader);

#if FEATURE_XML_SCHEMA
                    // Validate against schema on targets where schema is supported
                    using (var xsdStream = typeof(TargetMapper).Assembly.GetManifestResourceStream("Microsoft.Fx.Portability.Targets.xsd"))
                    {
                        var xmlReaderSettings = new XmlReaderSettings
                        {
                            DtdProcessing = DtdProcessing.Prohibit,
                            XmlResolver = null
                        };

                        using (var xmlSchemaReader = XmlReader.Create(xsdStream, xmlReaderSettings))
                        {
                            var schemas = new XmlSchemaSet();
                            schemas.Add(null, xmlSchemaReader);
                            doc.Validate(schemas, (s, e) => { throw new TargetMapperException(e.Message, e.Exception); });
                        }
                    }
#endif

                    foreach (var item in doc.Descendants("Target"))
                    {
                        var alias = (string)item.Attribute("Alias");
                        var name = (string)item.Attribute("Name");

#if !FEATURE_XML_SCHEMA
                        // We must manually check this now that schema validation is not available
                        if (alias == null || name == null)
                        {
                            throw new TargetMapperException(string.Format(CultureInfo.CurrentCulture, LocalizedStrings.MalformedMap, path));
                        }
#endif
                        AddAlias(alias, name);
                    }
                }
            }
            catch (XmlException e)
            {
                var message = string.Format(CultureInfo.CurrentCulture, LocalizedStrings.MalformedMap, e.Message);

                if (!string.IsNullOrEmpty(path))
                {
                    message = string.Format(CultureInfo.CurrentCulture, "{0} [{1}]", message, path);
                }

                throw new TargetMapperException(message, e);
            }
        }