System.Xml.XmlTextReader.GetNamespacesInScope C# (CSharp) Method

GetNamespacesInScope() public method

public GetNamespacesInScope ( XmlNamespaceScope scope ) : string>.IDictionary
scope XmlNamespaceScope
return string>.IDictionary
        public IDictionary<string, string> GetNamespacesInScope(XmlNamespaceScope scope)
        {
            return _impl.GetNamespacesInScope(scope);
        }
#pragma warning restore 3002

Usage Example

Example #1
0
		/// <summary>
		/// Gets the parent element path based on the index position. This
		/// method does not compact the path so it will include all elements
		/// including those in another namespace in the path.
		/// </summary>
		static XmlElementPath GetFullParentElementPath(string xml)
		{
			XmlElementPath path = new XmlElementPath();
			IDictionary<string, string> namespacesInScope = null;
			using (StringReader reader = new StringReader(xml)) {
				using (XmlTextReader xmlReader = new XmlTextReader(reader)) {
					try {
						xmlReader.XmlResolver = null; // prevent XmlTextReader from loading external DTDs
						while (xmlReader.Read()) {
							switch (xmlReader.NodeType) {
								case XmlNodeType.Element:
									if (!xmlReader.IsEmptyElement) {
										QualifiedName elementName = new QualifiedName(xmlReader.LocalName, xmlReader.NamespaceURI, xmlReader.Prefix);
										path.AddElement(elementName);
									}
									break;
								case XmlNodeType.EndElement:
									path.Elements.RemoveLast();
									break;
							}
						}
					} catch (XmlException) {
						namespacesInScope = xmlReader.GetNamespacesInScope(XmlNamespaceScope.All);
					}
				}
			}
			
			// Add namespaces in scope for the last element read.
			if (namespacesInScope != null) {
				foreach (KeyValuePair<string, string> ns in namespacesInScope) {
					path.NamespacesInScope.Add(new XmlNamespace(ns.Key, ns.Value));
				}
			}
			
			return path;
		}
All Usage Examples Of System.Xml.XmlTextReader::GetNamespacesInScope