private void EnqueuePrefixDefinition(XamlAttribute attr) { string prefix = attr.XmlNsPrefixDefined; string xamlNamespace = attr.XmlNsUriDefined; _parserContext.AddNamespacePrefix(prefix, xamlNamespace); XamlScannerNode node = new XamlScannerNode(attr); node.NodeType = ScannerNodeType.PREFIXDEFINITION; node.Prefix = prefix; node.TypeNamespace = xamlNamespace; _readNodesQueue.Enqueue(node); }
private void Initialize(XmlReader givenXmlReader, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings) { XmlReader myXmlReader; _mergedSettings = (settings == null) ? new XamlXmlReaderSettings() : new XamlXmlReaderSettings(settings); //Wrap the xmlreader with a XmlCompatReader instance to apply MarkupCompat rules. if (!_mergedSettings.SkipXmlCompatibilityProcessing) { XmlCompatibilityReader mcReader = new XmlCompatibilityReader(givenXmlReader, new IsXmlNamespaceSupportedCallback(IsXmlNamespaceSupported) ); mcReader.Normalization = true; myXmlReader = mcReader; } else { //Don't wrap the xmlreader with XmlCompatReader. // Useful for uses where users want to keep mc: content in the XamlNode stream. // Or have already processed the markup compat and want that extra perf. myXmlReader = givenXmlReader; } // Pick up the XmlReader settings to override the "settings" defaults. if (!String.IsNullOrEmpty(myXmlReader.BaseURI)) { _mergedSettings.BaseUri = new Uri(myXmlReader.BaseURI); } if (myXmlReader.XmlSpace == XmlSpace.Preserve) { _mergedSettings.XmlSpacePreserve = true; } if (!String.IsNullOrEmpty(myXmlReader.XmlLang)) { _mergedSettings.XmlLang = myXmlReader.XmlLang; } IXmlNamespaceResolver myXmlReaderNS = myXmlReader as IXmlNamespaceResolver; Dictionary <string, string> xmlnsDictionary = null; if (myXmlReaderNS != null) { IDictionary <string, string> rootNamespaces = myXmlReaderNS.GetNamespacesInScope(XmlNamespaceScope.Local); if (rootNamespaces != null) { foreach (KeyValuePair <string, string> ns in rootNamespaces) { if (xmlnsDictionary == null) { xmlnsDictionary = new Dictionary <string, string>(); } xmlnsDictionary[ns.Key] = ns.Value; } } } if (schemaContext == null) { schemaContext = new XamlSchemaContext(); } _endOfStreamNode = new XamlNode(XamlNode.InternalNodeType.EndOfStream); _context = new XamlParserContext(schemaContext, _mergedSettings.LocalAssembly); _context.AllowProtectedMembersOnRoot = _mergedSettings.AllowProtectedMembersOnRoot; _context.AddNamespacePrefix(KnownStrings.XmlPrefix, XamlLanguage.Xml1998Namespace); Func <string, string> namespaceResolver = myXmlReader.LookupNamespace; _context.XmlNamespaceResolver = namespaceResolver; XamlScanner xamlScanner = new XamlScanner(_context, myXmlReader, _mergedSettings); XamlPullParser parser = new XamlPullParser(_context, xamlScanner, _mergedSettings); _nodeStream = new NodeStreamSorter(_context, parser, _mergedSettings, xmlnsDictionary); _current = new XamlNode(XamlNode.InternalNodeType.StartOfStream); // user must call Read() before using properties. _currentLineInfo = new LineInfo(0, 0); }