public GetNamespacesInScope ( XmlNamespaceScope scope ) : string>.IDictionary |
||
scope | XmlNamespaceScope | |
return | string>.IDictionary |
/// <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; }
public static XmlElementPath GetParentElementPathCore(string xml) { XmlElementPath path = new XmlElementPath(); try { StringReader reader = new StringReader(xml); XmlTextReader xmlReader = new XmlTextReader(reader); xmlReader.XmlResolver = null; while (xmlReader.Read()) { switch (xmlReader.NodeType) { case XmlNodeType.Element: if (!xmlReader.IsEmptyElement) { QualifiedName elementName = new QualifiedName(xmlReader.LocalName, xmlReader.NamespaceURI, xmlReader.Prefix); path.Elements.Add(elementName); path.Namespaces = xmlReader.GetNamespacesInScope(XmlNamespaceScope.All); } break; case XmlNodeType.EndElement: path.Elements.RemoveLast(); break; } } } catch (XmlException) { // Do nothing. } catch (WebException) { // Do nothing. } return path; }
/// <summary> /// This method checks if the attached /// </summary> /// <param name="element"></param> /// <param name="reader"></param> /// <returns></returns> private static bool CheckIfNameSpaceDAVSpace(String element, XmlTextReader reader) { // split the element into tag and field String[] fields = element.Split(':'); // could be that the element has no namespace attached, so it is not part // of the webdav response if (fields.Length == 1) return false; // get the namespace list IDictionary<String, String> nameSpaceList = reader.GetNamespacesInScope(XmlNamespaceScope.All); // get the namespace of our node if (!nameSpaceList.ContainsKey(fields[0])) return false; // get the value String NsValue = nameSpaceList[fields[0]]; // compare if it's a DAV namespce if (NsValue.ToLower().Equals("dav:")) return true; else return false; }
public static IDictionary<string, string> GetNamespacesInScope(string xml) { try { var xmlReader = new XmlTextReader(new StringReader(xml)); xmlReader.XmlResolver = null; while (xmlReader.Read()) { switch (xmlReader.NodeType) { case XmlNodeType.Element: return xmlReader.GetNamespacesInScope(XmlNamespaceScope.All); } } } catch (XmlException) { /* Do nothing. */ } catch (WebException) { /* Do nothing. */ } return null; }